Jump to content

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


spawnLevel: (player, levelUnlock) => {
if (this.enableWeapon) {
Link to comment
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) {


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...