Problems animating sprites with javaS canvas

2

I'm trying to animate some Sprites Sheets, but I'm having a problem with a certain "shadow" that remains after the canvas runs the animation frame, it would be the previous frame, I can not fix it.

Full code in JSFiddle: link .

I think the error is in the loop that does not remove the data from the previous frame, but I have no idea how to remove it from the array, I would be grateful for any help you could offer.

    
asked by anonymous 25.11.2015 / 03:14

1 answer

1

You need to wipe the canvas between one drawing and another:

this.draw = function (x, y) {
   canvas.context.clearRect(0, 0, largura, altura);
   ...

Example in jsFiddle . I did not quite understand your code, so this example uses height and width hardcoded , so you need to adapt it to use the true width and height of the canvas.

    
25.11.2015 / 04:04