Jump to content

Saving game timer events during switch between states


Rustam
 Share

Recommended Posts

You can't, lots of stuff gets destroyed when switching states. Here's a link to the function in the StateManager that does it: https://github.com/photonstorm/phaser/blob/8399073fde8e242ef0a5beddcf165bc0c7fc84f0/src/core/StateManager.js#L401

So you want to save timer events -- how come? What problem is this a solution for?

Link to comment
Share on other sites

I have got 2 states: Win and Ready. On Win state I am showing win panel and starting timer for animate to collect my WonScores to TotalScores. But I need to switch to Ready state immediately after Win (after showing panel), NOT after win timer complete.

Link to comment
Share on other sites

It kinda sounds like you need to maybe cancel the timers and immediately run their callbacks on state change?

When it's phrased like that, you could do something like this:

var timeEvent = this.game.timer.events.add(this.myFunction, this);
/// ...then, later, on state change...
this.game.timer.events.remove(timeEvent);
timeEvent.callback.call(timeEvent.callbackContext);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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