Fire Weapons with Key.addListener

Optimize Laser Movement

OK, we have a situation where the processor has to work too hard keeping track of laser beams that don't exist. The problem lies with the for loop, which starts counting at 0. Even though laser0, laser1, laser2 (and so on) might be removed, the for loop will still reference them. That's no good.

Let's create a "floor", so the for loop starts counting from the lowest existing laser. We'll call that variable lFloor:

After each laser is removed, we will increment lFloor:

And let's not forget to declare lFloor at the start of the script:

Test again. I dropped some dynamic text boxes on the Stage so you can see exactly what the lFloor and lCount variables are doing:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player