uzet1 Posted March 17, 2019 Share Posted March 17, 2019 Hi, I have a group of items that their y position in increased by 1 during update I want to remove every item the its y is bigger than 600. I'm using kill() enemiesGroup.forEach(function(item){ item.position.y+=1; if(item.position.y>500){ item.kill(); } },this); but this only kill the item's spot but the group has the same length. As the group size is increased every x seconds, the size of the group will get really big over time How can I kill/remove the item and keep the size of the group to the real number of items? TNX Link to comment Share on other sites More sharing options...
dude78 Posted March 18, 2019 Share Posted March 18, 2019 According to documentation. https://photonstorm.github.io/phaser-ce/ -> https://photonstorm.github.io/phaser-ce/Phaser.Group.html -> You must guess, you are looking for method, so: https://photonstorm.github.io/phaser-ce/Phaser.Group.html#toc-5 -> And looking for sth that contains "remove": https://photonstorm.github.io/phaser-ce/Phaser.Group.html#remove Link to comment Share on other sites More sharing options...
theNeedle Posted March 18, 2019 Share Posted March 18, 2019 You need to `destroy` or `remove` item to remove it from group. `kill` only sets `alive`, `exists` and `visible` properties to false. It won't remove it from group. Since you're creating and destroying items frequently. Better approach would be to do object pooling. When item goes below 500, you `kill` it and when you want new item you find in the group for items which `alive` is set to false. and `revive` that item and change positions of that item. Link to comment Share on other sites More sharing options...
Recommended Posts