willdta Posted March 13, 2018 Share Posted March 13, 2018 Using Phaser IO, I'm trying to kill off another sprite that's currently not in a collision detection. I have a collision set with the player sprite and a treasure chest and what I want to do is on collision with the treasure chest, kill off another sprite to unlock a level but that sprite is not set in the collision. How do you got about handle 3 way collisions where 1 sprite is not included with the collision? The 3 items are player, treasure, and levelUnlock player is colliding with treasure game.physics.arcade.collide(player, treasure, this.spawnWeapon, null, this) game.physics.arcade.collide(player, treasure, this.spawnLevel, null, this) spawnWeapon: function(player, treasure) { this.enableWeapon = true treasure.kill() } spawnLevel: (player, levelUnlock) => { if (this.enableWeapon) { levelUnlock.kill() } Link to comment Share on other sites More sharing options...
samme Posted March 13, 2018 Share Posted March 13, 2018 You just need to create and keep a reference to the third sprite somehow. var player, treasure, levelUnlock; var state = { create: function () { levelUnlock = this.add.sprite(/*…*/); }, update: function () { game.physics.arcade.collide(player, treasure, this.collidePlayerVsTreasure, null, this); }, collidePlayerVsTreasure: function(_player, _treasure) { levelUnlock.kill(); _treasure.kill(); } } Link to comment Share on other sites More sharing options...
Recommended Posts