override Posted March 24, 2016 Share Posted March 24, 2016 How can i remove a object from a group on a collision? This is what i have so far // preload preload: function() { this.coin = game.add.group(); // Create a group this.coin.enableBody = true; // Add physics to the group this.coin.createMultiple(10, 'coin'); // Create 20 snow //in update update: function() { game.physics.arcade.overlap(this.bird, this.coin, this.getCoin(this.coin), null, this); //in getCoin function getCoin: function(item){ this.coin.remove(item); Link to comment Share on other sites More sharing options...
override Posted March 26, 2016 Author Share Posted March 26, 2016 getCoin: function(item){ this.coin.forEach(function(item) { if(game.physics.arcade.overlap(this.bird, item, null, null, this)){ item.kill(); // item.revive(); } }, this); } Figured it out this is what i have for anyone else who might need it Link to comment Share on other sites More sharing options...
AzraelTycka Posted March 27, 2016 Share Posted March 27, 2016 You don't need to go through your coin group (for clarity I would call it coins considering it's a group full of coins and coin only one element of that group ;-)) like that. Overlap works on groups and straight away calls your callback function with items which overlapped. game.physics.arcade.overlap(this.bird, this.coin, this.killCoin, null, this); killCoin: function(bird, coin){ coint.kill(); // coin.revive(); } You are basically forcing phaser to call overlap several times while it already gave you what you wanted. Link to comment Share on other sites More sharing options...
Recommended Posts