PDA

View Full Version : how to pause a setInterval



chroma
September 19th, 2006, 03:55 AM
Hello everyone. This is my first post on this forum, as been a guest in here for quite a while.
Okay, let me guide you directly to my problem.

I'm currently programming a strategy game, with timeline (month, year) 15 years duration.
Im doing a setInterval on this one, which works perfectly well UNTIL I have to make a pause-function. My first thought was to save the currently month and year in variables, clear the setInterval and start the same setInterval again, using if/elses and make the timeline start from where it stopped when the pause is off.

Then the problem comes up. If I was in eg. late june 2000, the game starts again at the start of june 2000. (Which makes an awful bug in the game)

Do I really have to "break down" the timeline into pieces, or is it a better way to pause my setInterval function?

The code is quite a bit, so at first I just want your thoughts about how to pause a setInterval to get it start from exactly the same ms it stopped.
In my opinion there should really be a predefined setInterval pause-function in flash.

Any help appreciated:ear:

-Z-
September 19th, 2006, 11:08 PM
I'm a very simple minded person... but if I were you...

I would so something like this


int_start = getTimer();
intt = setInterval(functionname, 1000); //that allows 1 second for example


//somone presses pause...
clearInterval(intt);
int_end = getTimer();
...
...
//somone un pauses
intt = setInterval(functionname, 1000-(int_end-int_start));




But like I said, I always look for the simple way out of every solution... :/ I'm not much for those complex codes