I made a platformer using ctx.clearRect and ctx.fillRect, so each time the player moved I would just delete the previous position and draw him again.
Now I'm working on importing my own art into the game and I'm having problems removing the previously drawn image.
Example of some of the code I am using now to render the player:
var playerReady = false;
var playerImage = new Image();
playerImage.onload = function () {
playerReady = true;
};
playerImage.src = "images/player.png";
var render = function () {
if (playerReady) {
ctx.drawImage(playerImage, player.x, player.y);
}
};
So Im wondering if there is anything similar to ctx.clearRect for ctx.drawImage or what I could do, my current workaround is to render the whole background on top of the previously drawn background + player but this is not ideal for what I´m trying to do.
thank you!