PDA

View Full Version : (Pause game) A way to make everything stop and playplay


josh_tamugaia
07-21-2005, 09:07 AM
Hi!

I've seen flash games that have a pause feature. For example, when I press Space, everything freezes, including script powered moving movie clips.

Then when I press Space again, everything continues to run as normal.

(Using Space to toggle pause)

I've searched high and low but could not find the way to do this. Is there a special command used to freeze the whole flash movie while it's playing and unfreeze it?

Please reply. Thanks in advance!

Josh Tamugaia

emergency_pants
07-21-2005, 10:23 AM
I don't know whether there's a quicker way to this, but what I usually do is have a variable such as

var gameOn:Boolean;

In my game scripts, I would test to make sure gameOn is true before running my main functions.

eg:

function playerSequence(){
if (gameOn){
playerMoveCalc();
playerHitTests();
playerMove();
}

sasuke
01-18-2008, 02:03 PM
I working on new component called PauseComponent. it can pause movieclip (with or without instance name!), onEnterFrame, mouse & key listener and sound.also it can disable an enabled btn or movieclip.
its perfect for flash games

scarce
01-18-2008, 09:16 PM
well the best way I can think of that I'd use would be:


paused = false
//Replace the below code to whatever function your games main process is running on
this.onEnterFrame = function(){
if(paused == false){

//ALL of your code for the game is in here
if(Key.isDown(Key.SPACE)){
paused = true
}
}else{
if(Key.isDown(Key.SPACE){
paused = false
}
}
}


try that

ASWC
01-18-2008, 09:49 PM
The principle is good but I don't think you want to switch the boolean inside an onEnterFrame function. (do a trace, hold the spacebar and see...)

sasuke
01-19-2008, 05:01 AM
try this

this.onEnterFrame=function(){
if(Key.isDown(Key.SPACE)){
!pause? (pause=true) : (pause=false)
}
}