How do I best remove an entity from my game loop when it is dead?
Posted
by
Iain
on Game Development
See other posts from Game Development
or by Iain
Published on 2010-08-12T19:10:55Z
Indexed on
2012/10/28
17:20 UTC
Read the original article
Hit count: 216
game-loop
Ok so I have a big list of all my entities which I loop through and update. In AS3 I can store this as an Array (dynamic length, untyped), a Vector (typed) or a linked list (not native). At the moment I'm using Array but I plan to change to Vector or linked list if it is faster.
Anyway, my question, when an Entity is destroyed, how should I remove it from the list? I could null its position, splice it out or just set a flag on it to say "skip over me, I'm dead." I'm pooling my entities, so an Entity that is dead is quite likely to be alive again at some point. For each type of collection what is my best strategy, and which combination of collection type and removal method will work best?
© Game Development or respective owner