Hi,
need some guidance here… I read about grouping objects and removing groups but can’t find a solution that fits into my project. (It’s my very first project and I’m not using scenes…)
Basically I have the play screen in wich is spawn a single enemy at a time. Every time it’s killed the ‘spawn enemy’ function is called in order to spawn another one. If game over occurs, the current enemy still on screen gets eliminated by using the relative commands in the ‘killenemy’ function (i don’t call the ‘killenemy’ function itself just implemented its commands I need into the ‘gameover’ function).
This works fine as long I want just one enemy spawn at a time. Now I would like to spawn multiple enemies at the same time wich I do by recalling the spawning function inside from within itself (at random times).
So basically now I have several enemy on screen simultaneously and they are ‘identical’ cause spawned by the same function. If I kill them individually in game it’s fine, problems arise when game over occurs: when it happens only one of them gets eliminated by the gameover function as the others remain on the gameover screen.
So I tried to put every enemy spawned inside the same group
enemies = display.newGroup( )
enemies: insert (enemy)
by inserting the above code in the spawn enemy function, and this piece of code
transition.cancel ()
enemies:removeSelf ()
enemies = nil
in the game over function to eliminate the group and its childs.
If I run the program with these pieces of code implemented it works smooth without returning errors as long as only one enemy is spawned at a time. Once I make the spawnenemy function spawn multiple enemies the same problem occurs. only one enemy of the group is removed once by game over.
Any idea on where the problem might reside???
Thanks.