fubeca6 Posted September 7, 2014 Share Posted September 7, 2014 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 More sharing options...
eguneys Posted September 7, 2014 Share Posted September 7, 2014 I don't know about physics and collision, so i can't help what might be causing the delay. What platform do you test? Meanwhile as a workaround you might test a blink flag in your death function.function death() { if (this.burn.alpha !== 0) { this.player.kill(); }} Link to comment Share on other sites More sharing options...
fubeca6 Posted September 9, 2014 Author Share Posted September 9, 2014 I appreciate the answer, Eguneys, but unfortunately that didn't quite fix the problem. Link to comment Share on other sites More sharing options...
lewster32 Posted September 9, 2014 Share Posted September 9, 2014 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 More sharing options...
Recommended Posts