Jump to content

Overlap Event Firing Twice, Can't Stop It


ashes999
 Share

Recommended Posts

TLDR: overlap callbacks happen twice even when I destroy objects and change scenes, can I stop this somehow? You can see it here:

 

Longer version: I'm using group.overlap(this.player, this.transitionTiles, function(...)) to detect when the player steps on a transition tile and should move to the next screen. When the user steps on two simultaneously, the transition happens twice. (I can't just make the gap one tile high because you'll never be able to step on it).

 

This appears very odd, because I am literally destroying all the objects, groups, and even (for illustrative purposes) changing the game state to something totally different -- you can see from the TLDR case above that you're shoved back to the titlescreen.

 

I would think destroying the original group, and tiles, and even changing the state would abort the second event from firing. But it seems that it's queued up internally, and I can't avoid it.

 

I'm pretty sure this is causing more bugs (try transitioning maps a few times).

 

How can I fix this?

 

(P.S. it's all CoffeeScript but you're welcome to look at the source, or generated Javascript, if you want)

Link to comment
Share on other sites

The simplest way around this would be to mark with a flag when the action has been performed so it won't be performed twice - something along the lines of:

var hasExit = false;game.physics.arcade.overlap(player, tiles, function(player, tile) {  if (!hasExit) {    hasExit = true;    // ... do your exit routine here - it will only be called once  }});
Link to comment
Share on other sites

I tried this and it didn't work.

 

I debugged into Phaser. It processes all events in a for-loop. Even when I change state, it's basically impossible to stop the event processing.

 

There's something weird going on with variable values. To use your code as an example, hasExit is set to true, but both events fire and print out that it's false. I can't figure out what the cause is there.

 

I also discovered that most of the other bugs are my fault (no surprise there). I still would like a way around this. It appears benign, though, that the transition happens twice.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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