Sign in to follow this  
willdta

Kill a sprite with Collision

Recommended Posts

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()
}
 
 

Share this post


Link to post
Share on other sites

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();
  }
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.