ashes999 Posted October 29, 2014 Report Share Posted October 29, 2014 TLDR: overlap callbacks happen twice even when I destroy objects and change scenes, can I stop this somehow? You can see it here:Browse to http://ashes999.github.io/sword-of-eman/?debug=trueWalk all the way to the right, through the gap, and to the next screenNote the debug console says "****** Move done." twice. 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) Quote Link to comment Share on other sites More sharing options...
lewster32 Posted October 30, 2014 Report Share Posted October 30, 2014 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 }}); Quote Link to comment Share on other sites More sharing options...
ashes999 Posted November 2, 2014 Author Report Share Posted November 2, 2014 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. Quote Link to comment Share on other sites More sharing options...
lewster32 Posted November 3, 2014 Report Share Posted November 3, 2014 This sounds to me like the event is being added twice somewhere maybe, and both added events are firing simultaneously. Even then though, the flag driven method above should ensure the action only happens once regardless, so I'm not sure at all what's going on there. Quote Link to comment Share on other sites More sharing options...
ashes999 Posted November 3, 2014 Author Report Share Posted November 3, 2014 This was fixed due to yet another bug in my transitioning code. Epic fail. lewster32 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.