jflowers45 Posted March 27, 2014 Share Posted March 27, 2014 I'd like to have a timer that persists even when you switch states. I usually create timers using something like this myTimer=game.time.create(false);myTimer.loop(1, this.someFunction, this); //EVERY MILLISECOND EXECUTIONmyTimer.start(); but whenever I switch states those timers get cleared. I do want everything else cleared so I don't want to change the value of 'clearWorld' that gets passed to game.state.start Any ideas? Is there a way I can just 'subscribe' any object to the game's main update loop? Link to comment Share on other sites More sharing options...
plicatibu Posted March 27, 2014 Share Posted March 27, 2014 I don't know whether it's possible but maybe you could create both timer and its callback on main namespace. Regards. Link to comment Share on other sites More sharing options...
Heppell08 Posted March 27, 2014 Share Posted March 27, 2014 Create it in boot maybe? I'm unsure about timers but I made a variable in my boot the stores numbers across multiple states. Just put the var in global and create in create and see if it stores the timing. Totally new concept with it needing to loop. Link to comment Share on other sites More sharing options...
jflowers45 Posted March 27, 2014 Author Share Posted March 27, 2014 Heppell08 - that was my first thought too - i tried creating it in preload/boot but as long as the timer gets created via game.time.create it gets cleared between states. plicatibu - sort of along those lines, what I've ended up doing is just using requestAnimationFrame. Basically I'm just using this for a nice animation while it changes states, so that has worked ok - i'm hoping to post an example of what I ended up doing and having rich show me a 'better' way because there's gotta be one Link to comment Share on other sites More sharing options...
Xej Posted January 7, 2015 Share Posted January 7, 2015 Hey folks, I have the same problem as jFlowers45 and tried a lot of different things before i found this thread. Has anybody got any further progress on that problem and/or a solution? @jflowers45 how is your solution working? I don't understand the hints in your last post. Do you have maybe a small example? Thx in advance Link to comment Share on other sites More sharing options...
Recommended Posts