Jump to content

forEachDead is being called to little times


liorfrenkel
 Share

Recommended Posts

Hi,

I have this code:

console.log("top dead: " + this.topGrp.countDead()); // 3
                this.topGrp.forEachDead((child) => {
                    console.log("destroy top"); // only 2 times in chrome's console
                    child.destroy();
                }, this);

topGrp is a group
the function countDead() returns 3, and then forEachDead is iterating only 2 time, I see this in the console and only 2 object in my game are destroyed...

help??

thanks!
Lior

Link to comment
Share on other sites

I suspect it has to do with the fact that you are destroying the children in the loop.

I haven't tested anything, but I'm reading through the code for Group.iterate (https://github.com/photonstorm/phaser/blob/v2.4.4/src/core/Group.js#L1702) and I see that they using a for loop that checks the length of Group.children after each iteration. Because you are destroying children in the loop, the length of Group.children changes, causing the iteration to quit prematurely. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...