Jump to content

Odd Overlap Behavior


fubeca6
 Share

Recommended Posts

Good Evening,

 

In my little project, I have a tile that blinks - when it is "on", it will player.kill(). However, when it is "off" the player can pass by unharmed. 

 

Now, here's the problem: when the player passes by, there seems to be some delay, so that even though the player is not longer in the blink-tile's space, it will player.kill(). I'm not sure why this is happening, but it's very frustrating for my alpha testers - my kids :)

 

Here's my relevant code:

function update() {	game.physics.arcade.collide(this.player, this.burn, death, null, this);}function death() {        this.player.kill();}

As always, your help is greatly appreciated - overall, I've been very impressed with the Phaser community so far!

 

Thanks

Link to comment
Share on other sites

The delay is likely caused by the difference in position between the bodies of moving objects and their sprites. If you debug the body of your player and burn, you will see where the actual locations of the bodies are and it may shed some light on the problem:

function render() {  game.debug.body(this.player);  game.debug.body(this.burn);}

To fix this, you could maybe instead of using physics overlap, use Sprite.overlap in your update method, something like this:

function update() {  if (this.player.alive && this.burn.alpha > 0 && this.burn.overlap(this.player)) {    this.player.kill();  }}

This method will check the bounds of the two objects' sprites for intersection, rather than the bodies, so it will be totally accurate to what Phaser is rendering. Replace the alpha check with whatever criteria you use to determine the burn sprite being 'on' and 'off'.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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