1 decade ago by jminor
If you call this.kill() from inside an entity's update() function, then the next entity in the scene will not be updated that frame. This is because game.update() iterates over the list of entities by index, but kill() removes one from the list.
There is a similar problem where calling ig.game.loadLevel() inside an update function will cause odd behavior since the list of entities has been completely swapped out in the middle of the update loop. For example, entities early in the new level's list will be drawn before their first update is called.
Here are a few ways to fix these bugs: 1. Make a copy of the entities list and iterate over that. 2. Iterate over the list backwards. 3. Defer the removal of entities and level switch until after the loop is done.
There is a similar problem where calling ig.game.loadLevel() inside an update function will cause odd behavior since the list of entities has been completely swapped out in the middle of the update loop. For example, entities early in the new level's list will be drawn before their first update is called.
Here are a few ways to fix these bugs: 1. Make a copy of the entities list and iterate over that. 2. Iterate over the list backwards. 3. Defer the removal of entities and level switch until after the loop is done.