Page 1 of 1

Best practice for removing all objects when changing state

Posted: Mon Dec 01, 2014 4:39 am
by rrTea
Right now I have it set up that when the player gets hit, the State switches from "Arena" (removes all models OnLeave) to "Game Over" screen.

The problem is that the majority of enemies have a pretty simple

+OnRemove:
=Play some sound
=Spawn "Flash" model for explosion

setup, which is generally fine, but doesn't work well in this context because when all the enemies get removed at the same time explosions can be both heard and seen in the next State etc.

I can partially solve this by putting a OnStart:RemoveAllModels in the "Game Over" state too (or have a middle State with a just RemoveAllModels + proceed to "Game Over") which would remove the explosions, but this sounds like a bad workaround and still doesn't solve the problem of exploding sound carrying over.

To avoid this I can make it so that some enemies explode only when their Hitpoints reach 0, but I'm trying to avoid that because many simple enemies do not have nor need hitpoints at all (explode as soon as they get hit).

There must be a better way to go about this?

Posted: Mon Dec 01, 2014 8:34 am
by VilleK
Hi,

I looked my own projects ZBlast and TripleE (both which are included in the ZGE distribution) and see that I use OnCollision instead of OnRemove to spawn explosions. Maybe you can use that too?

Posted: Mon Dec 01, 2014 9:59 am
by rrTea
Hi,

Yes I thought of that too, I'll definitely have to reorganize it a bit. Will post the results on weekend.