Skip to main content

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)

im writing a platformer and want to implement own art, now i know how to display it and this isn't my question. It rather is how do i remove it? I tried drawing a rectangle over it and removing it, but that doesn't seem to work heres 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++;
        }
    }
}

im using some arrays to store the image data such as the location and an id form management, but i didn't implement a method yet to get the dimensions of it thats why im giving it the size parameters. (Strangely it works if i enter the fillRect and clearRect commands in the console)

I'm writing a platformer and I want to implement own art, now I know how to display it and this isn't my question. It rather is how do I remove it? I tried drawing a rectangle over it and removing it, but that doesn't seem to work, 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++;
        }
    }
}

I'm using some arrays to store the image data such as the location and an id form management, but I didn't implement a method yet to get the dimensions of it, thats why I'm giving it the size parameters. (Strangely it works if I enter the fillRect and clearRect commands in the console)

Source Link
Betrahm
  • 11
  • 1
  • 1
  • 2

JavaScript canvas remove image

im writing a platformer and want to implement own art, now i know how to display it and this isn't my question. It rather is how do i remove it? I tried drawing a rectangle over it and removing it, but that doesn't seem to work heres 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++;
        }
    }
}

im using some arrays to store the image data such as the location and an id form management, but i didn't implement a method yet to get the dimensions of it thats why im giving it the size parameters. (Strangely it works if i enter the fillRect and clearRect commands in the console)