13 Jul 2010
Pause A Flash Game With stage.frameRate
If you’re using a Flash/Flex framework (e.g. flixel) that controls everything in a highly centralised way then a pause feature is either going to be included or should prove easy to implement. But when making use of standard Flash timelines for animation & state it’s usually not so straightforward to make everything halt abruptly and then safely restart.
Providing you’re using ActionScript 3, there’s a quick’n’easy pause option to consider. When the player presses a certain key or clicks a button, you can almost stop the game using
stage.frameRate = 0.01;
This is the lowest value Flash currently permits, and a frame advance every 100 seconds is generally good enough for hours of pausing. The normal frame rate can then be reinstated when the game’s unpaused.
Other points to note:
- If you cover the whole game with something then you won’t have to worry about mouse interaction with buttons etc. while paused.
- Keyboard interactions will need to check a flag or the
frameRate
value directly if you want to deactivate them. - Sounds won’t get paused, but you could temporarily mute them (e.g. with
SoundMixer.soundTransform = new SoundTransform(0);
). - If you only want the pause feature to apply during actual gameplay, make sure the game unpauses itself if necessary on game over/complete, in case it ticks over into one of those states.
- Button and key events are independent of the frame rate, so your unpause key/button will work fine (including displaying Over/Down states).
Comments
Comments are now closed for this entry.