Jump to content

setting tileIndexCallback for specific sprite overlap


Phorey
 Share

Recommended Posts

Hi all,

I'm trying to detect player to tile overlapping:

// Set player spike collision detection
game.map.setTileIndexCallback(SPIKE_ID, function () {
  playerDeath(game);
}, game, game.worldLayer);

It works great, but the problem I'm running into is that if a sprite other than the player's sprite runs into the spike tile, the playerDeath function is called.

Is there a way to check if it's the player sprite overlapping with the tile before calling the playerDeath function?

I've tried making the spikes tile separate and hoped this would work:

function updateSpikeCollision(game) {
  game.physics.arcade.overlap(game.player, game.spikeLayer, function(player, spike) {
    console.log("overlapping");
  }, null, game);
},

But this callback gets triggered regardless of overlapping.

 

Any pointers would be appreciated!

Thanks

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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