Problems animating sprites with javas canvas

Asked

Viewed 54 times

2

I’m trying to animate some Sprites Sheets, but I’m having a problem regarding a certain "shadow" that is after the canvas runs the animation frame, it would be the previous frame, I can’t fix it.

full code in Jsfiddle : https://jsfiddle.net/JScheuermann/syn8uyr4/.

I believe 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 very grateful for any help you could offer.

  • Please include in the question the relevant code(s) chunk(s) instead of having all the code in an external link. The jsFiddle example is good as an additional feature, but ideally all the information needed to answer the question is right here in the question (suggest [Edit] making these adjustments).

1 answer

1


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

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

Example in jsFiddle. I don’t quite understand your code, so this example uses height and width hardcoded, it is therefore necessary to adapt it to use the true width and height of the canvas.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.