Pausing a Game with Timers

So right now the way this game works, basically, is that the Main class places the Level class on the stage once the play button has been clicked.

The Leven class has a few arguments including the amount of objects being created and the delay between each creation. This is done by creating a timer.

The problem is that also in the main class I have added a pause button that sets the framerate to 0 and stops the timer, as well as getting rid of events and etc. The problem is that when the game is unpaused, the timer is reset to 0.

Is there a good way to get around that, so the timer remembers its location? Why did Adobe not include that function?

What I mean to say is that the delay is restarted when the start() method is called.

So, the game stops, the frameRate is set to 0, the timer is stopped.

Then the game continues, frameRate is brought back to 24 and the timer starts(), however not from where it left off. So, if the player presses the pause button every 4 seconds (it’s a 5 second timer), the timer event listener function is never called.

So I guess the question is, how do you get a timer to remember where it was when it stopped and start it at that point?

Interesting problem. Unfortunately I can’t think of a way of solving it in a simple way using AS3’s Timer. I’d recommend building your own timer class which would have a start() and stop() method that behaves the way you want. Use flash.utils.getTimer to keep track of time and listen for ENTER_FRAME events. Or hope that someone else knows a better solution w/ AS3’s Timer.

It might be easier to handle all your timer needs through an enter-frame event. Then, when you kill the framerate to pause your game, everything will properly pick up where it’s supposed to when the game resumes.

Hey, do you like games? So do we — that’s what makes Kongregate the best source of free games online. We have thousands upon thousands of free online games, from both one-man indies and large studios, rated and filtered so you can play the best of the best. Read more »