Rustam Posted February 19, 2016 Share Posted February 19, 2016 Hello! How to save game timer events, when I switch to next state? I'm use: game.state.start(GameState[GameState.Win], false, false); But on Win state all timer events of previous state are destroyed :( Thanks. Link to comment Share on other sites More sharing options...
drhayes Posted February 19, 2016 Share Posted February 19, 2016 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? Rustam 1 Link to comment Share on other sites More sharing options...
Rustam Posted February 20, 2016 Author Share Posted February 20, 2016 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 More sharing options...
drhayes Posted February 22, 2016 Share Posted February 22, 2016 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 More sharing options...
Rustam Posted February 24, 2016 Author Share Posted February 24, 2016 Thanks, drhayes! I decided this question with a similar way Link to comment Share on other sites More sharing options...
Recommended Posts