Hi, sorry to bother but I really can’t get this to work.
I’m trying to remove all objects from an array, and then emptying the array using splice. I’m restarting the game, removing all objects etc so that I can add them again.
But what happens is that no object (enemies, blocks, bullets etc) is really removed. It’s not visible anymore, but it’s still on the stage wreaking havoc (hit detection still working, so enemies are avoiding enemies that were supposed to be removed, bullets hitting them and so on).
And then when I restart the game a couple of times I have way too many objects and the game starts to lag. Code below:
This is the code for the enemy, I have different loops for the other objects, but they all look the same:
for(var a=0; a<enemy1.length; a++) //loop through enemy1
{
if(enemy1[a].dead == true) //check if dead
{
removeChild(enemy1[a]); //remove from stage
enemy1.splice(a,1); //remove element from array
}
}
So to reiterate, I need to remove the objects from the stage, and clear/empty the array.
Thanks in advance, please help me :S