Does anyone know what I'm doing wrong here?
-
I have a sprite that's spawned every so often and it works but it has to shoot as well so I implemented the same shooting method as my other sprites but it gives me an error message I'm sure I'm doing something wrong.
-
Show the code where you populate the EnemyShip sprites. It seems that their is one sprite less than the code expects. What is maxEBS3? Is it a constant or can it change?
My guess is that you have maxEBS3 - 1 sprites to start with, and when you remove sprites from your array, the array shrinks, but you still go from 0 to maxEBS3 in your loop.
-
MaxEbs3 is my bullet sprites for my 4th enemy ship that shoots
-
@poof92 If your removeGameSprite() function is changing the size of the array (by copying it into a new array with the old element removed), then now your maxEbs3 variable will not correspond to the size of the array anymore.
You could try always using len() instead, so that it is checking the size of the array and never counts past it - but.. I think you will run into a problem.
I have tried a similar approach as this before to sprite handling, where you remove sprites from the arrays and remove the elements so that you never "waste" an iteration in your for loops - but this will end up skipping over sprites when you remove them.
You will need to change these for loops into while loops, using a manual counter variable which only increments when you do not remove a sprite. They would only loop while this counter is less than the len() of the array. When you remove one, and the array changes size, the index variable will now point to the next sprite along in the array, since they've all been shunted down.
Hope this makes sense.
-
Ok thanks a ton I'll give it a try