View Full Version : Pause button in a flash game
Mark Aged
06-01-2009, 12:19 PM
How do you go about making a pause button? I have an idea of how to make one for my game, but I want to know how you guys do it, so I can maybe do something better then setting all variables that control movement to 0, or whatever.
Put an if statement around all your code that says something like if(paused!=true){
Then have a button outside of that that toggles paused to true or false.
truimagz
06-01-2009, 01:30 PM
or better yet create a pause function that kills your game loop.
something like
function runGame ( Void ) : Void {
this.onEnterFrame = function ( ) {
///game code
}
}
function pauseGame ( Void ) : Void {
delete this.onEnterFrame;
//remove mouse listeners
//remove event listeners
};
magcius
06-01-2009, 02:56 PM
I do something like this:
function mainUpdate():Void {
// put all your onEnterFrame code in here.
}
function pauseGame():Void {
this.onEnterFrame = mainUpdate;
}
function resumeGame():Void {
this.onEnterFrame = null;
}
This way you're not creating, populating, and destroying anonymous code blocks which can take time in AVM1.
If this is AS3, do something like this:
function mainUpdate():void {
// same thing
}
function pauseGame():void {
this.addEventListener(Event.ENTER_FRAME, mainUpdate);
}
function resumeGame():void {
this.removeEventListener(Event.ENTER_FRAME, mainUpdate);
}
Mark Aged
06-03-2009, 11:23 AM
Thanks for the ideas guys, incredibly helpful.
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.