The problem of cleaning the canvas. Select Objects Not Cleansing in Canvasteroids

I am creating a new asteroid game with html5 canvas. Everything is going well, and I have to dynamically draw lasers on stage. They do not draw correctly (they should be only 10 pixels), and when you shoot twice in 10 seconds, an old laser path appears. Here's the url, because there is more code than I want everyone to skip.

http://marccannon.com/canvasteroids/

Ideally, lasers will have a length of 10 pixels and go away as soon as they go out of life (1 second or 33 frames). They get shift()from an array that should no longer run them in the drawing chain. There seems to be some kind of memory with a Laser object class. So far, I have spent hours in space art with laser trails instead of adding actual asteroids. Someone please help. I'm losing my mind.

Thanks in advance for your help.

+1
source share
1 answer

The problem is that by drawing on the canvas, you should always remember about the call beginPath(), otherwise all the teams moveToand lineTowill continue to add and add to the current path.

+5
source

All Articles