GoodOldSnoopy Posted March 27, 2017 Share Posted March 27, 2017 I'm having an issue which I'm unsure what's happening and can't find anyone else having a similar issue. Basically, I create a group, create them, add a tween to animate them across the page. I create a player sprite and whenever the player collides with the other sprites in the group kill them and render another one. however, this only works on the first item I create. var group = game.add.group(); group.enableBody = true; group.physicsBodyType = Phaser.Physics.ARCADE; So create my group and then do a `for loop` to create all my enemies for (var i = 0; i < 2; i++) { c = group.create(game.width, 20, 'seacreatures', 'octopus0000'); c.name = "enemy" + i; c.body.immovable = true; c.alive = true; c.alignIn(laneArr[Math.floor(Math.random() * laneArr.length)], Phaser.RIGHT_CENTER); game.add.tween(c).to({ x: -200 }, speedArr[Math.floor(Math.random() * speedArr.length)], Phaser.Quadratic, true, 0, 0, false); } group.callAll('animations.add', 'animations', 'swim', Phaser.Animation.generateFrameNames('purpleFish', 0, 32, '', 4), 30, true, false); group.callAll('play', null, 'swim'); game.physics.enable(c, Phaser.Physics.ARCADE); Below this I also render the player currPlayer = game.add.sprite(50, game.height / 4 * 2 + 45, "playerFish"); game.physics.enable(currPlayer, Phaser.Physics.ARCADE); currPlayer.body.immovable = true; currPlayer.physicsBodyType = Phaser.Physics.ARCADE; currPlayer.alignIn(laneRect_three, Phaser.LEFT_CENTER); currPlayer.scale.set(1.5); So in short, the enemy travels across the `x` axis and once it collides with the player it triggers a function which looks like this, my update function: game.physics.arcade.overlap(playerFish, enemyFish, collisionHandler, null, this); then the function it calls, `collisionHandler` looks like function collisionHandler () { killedEnemies += 1; c.destroy(); c.alive = false; text.setText("You have killed " + killedEnemies + " enemies !"); console.log("<<<<<<<<"); } But like I said, it only kills the first item it hits, am I missing anything? Link to comment Share on other sites More sharing options...
samme Posted March 27, 2017 Share Posted March 27, 2017 You need to work with the colliding objects themselves: function collisionHandler (player, enemy) { enemy.kill(); // … } Link to comment Share on other sites More sharing options...
GoodOldSnoopy Posted March 28, 2017 Author Share Posted March 28, 2017 16 hours ago, samme said: You need to work with the colliding objects themselves: function collisionHandler (player, enemy) { enemy.kill(); // … } Ahh I see. I did this, which works but for only the first one again. Basically, my `collisionHandler` only gets fired once after that even putting a `console.log()` in there doesn't work so it's not getting triggered. Link to comment Share on other sites More sharing options...
tru#_beast Posted June 27, 2017 Share Posted June 27, 2017 im having this problem also pls solve Link to comment Share on other sites More sharing options...
Recommended Posts