imI'm writing a platformer and I want to implement own art, now iI know how to display it and this isn't my question. It rather is how do iI remove it? I tried drawing a rectangle over it and removing it, but that doesn't seem to work heres, here's my code:
function clearImage(id) {
for (var i = 0; i < 6;) {
if (img_id[i] == id) {
console.log(img_loc_x[i]);
console.log(img_loc_y[i]);
ctx.fillRect(img_loc_x[i], img_loc_y[i], "1000", "1000");
ctx.clearRect(img_loc_x[i], img_loc_y[i], "1000", "1000");
img_loc_x[i] = null;
img_loc_y[i] = null;
img_id[i] = null
console.log("Cleared image with id: "+id+" succesfully!");
} else {
i++;
}
}
}
imI'm using some arrays to store the image data such as the location and an id form management, but iI didn't implement a method yet to get the dimensions of it, thats why imI'm giving it the size parameters.
(Strangely it works if iI enter the fillRectfillRect
and clearRectclearRect
commands in the console)