Jump to content

Create a timer that persists between state changes


jflowers45
 Share

Recommended Posts

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 EXECUTION

myTimer.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

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

  • 9 months later...

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

 Share

  • Recently Browsing   0 members

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