tackle Posted May 11, 2014 Share Posted May 11, 2014 I have a function 'checkHit' that calls..this.forEachAlive(this.calculateHit,this.game.physics,hitCirc,this);..where "this" in this case is a extended Group object. I do a check if enemies are hit when this is called (inside calculateHit), and if I hit an enemy that enemy is removed from the group. The problem then seems to be that since the enemy is removed, the iteration through all the enemies alive fails when it comes to the end - it looks for the last index but there is one index less now in the group. So I get this error:Uncaught TypeError: Cannot read property 'alive' of undefined Is my design fundamentally flawed initially, or should the Group function forEachAlive check for undefined first? Link to comment Share on other sites More sharing options...
XekeDeath Posted May 12, 2014 Share Posted May 12, 2014 My solution to this is a to use a temp array as a list of objects to be removed:var deleteme = [];group.forEachAlive(function(child) { //Do Stuff... deleteme.push(child);}for ( var ii = 0; ii< deleteme.length; ii++){ group.remove(deleteme[ii]);} tackle 1 Link to comment Share on other sites More sharing options...
Recommended Posts