Bobcp Posted September 20, 2015 Share Posted September 20, 2015 Hi, i try to create script which destroy all item in group, who leaves of screen if (snowball.x<-200){ snowball.destroy(); console.log('KILL'); } else{ snowball.body.velocity.x=-500; snowball.angle -= 3; }It work, but when i create another snowball in group, x position check only in last itemsnowball = snowballGroup.create(1000,this.game.world.height-100-heightGround, '/snowball.png');How to check position of all item in group? Thank you Link to comment Share on other sites More sharing options...
drhayes Posted September 21, 2015 Share Posted September 21, 2015 I'm not sure what your question is. Do you have a loop somewhere that is going through all the group's children? Link to comment Share on other sites More sharing options...
Bobcp Posted September 21, 2015 Author Share Posted September 21, 2015 I'm not sure what your question is. Do you have a loop somewhere that is going through all the group's children? I have a code where i create a group, and start events loop.this.snowballGroup = this.game.add.group();this.snowballGroup.enableBody = true;this.snowballGenerator = this.game.time.events.loop(Phaser.Timer.SECOND * 3, snowballCreate, this); function snowballCreate() { this.snowball = this.snowballGroup.create(1000,this.game.world.height-100-heightGround, '/snowball.png'); this.snowball.body.gravity.y = 2000; this.snowball.body.bounce.y = 0.1; this.snowball.anchor.setTo(0.5, 0.5); } I need a script where the children are destroy if they go over the screen.if(snowball.x<-200){ snowball.destroy(); console.log('KILL');}else{ snowball.body.velocity.x=-500; snowball.angle -= 3;}My script does not work, it only removes the first children. Link to comment Share on other sites More sharing options...
Bobcp Posted September 21, 2015 Author Share Posted September 21, 2015 I try thisthis.snowballGroup.forEach(function(snowball) { if(this.snowball.x<-200){ this.snowball.destroy(); this.snowballGroup.remove(this.snowball); console.log('KILL'); } else{ this.snowball.body.velocity.x=-500; this.snowball.angle -= 3; }},this);but when i create a new child, check from snowball.x begins with new child, and stops with previous Link to comment Share on other sites More sharing options...
Bobcp Posted September 22, 2015 Author Share Posted September 22, 2015 I solved the problem with this codesnowballGroup.forEachAlive(function(snowball) { if(snowball.x<-200){ snowball.destroy(); console.log('KILL'); } else{ snowball.body.velocity.x=-500; snowball.angle -= 3; }});forEachAlive find all children and check it. Thank you, all Link to comment Share on other sites More sharing options...
Recommended Posts