View Full Version : [AS3] how do i pause my game for a couple seconds?
ladel
07-01-2009, 08:35 PM
so here's the deal: theres a boss and when you beat him, i want the words LEVEL 2 to flash and the game to pause for a second so the user know that something is about to change. I got the letters to flash, but i can't figure out how to delay the game.
I tried _root.pauseMovie() and clearInterval() but they dont seem to be working, and I'm sure this is a really easy thing to do and I'm just being a noob. Please help?
-Dan
bluemagica
07-01-2009, 09:57 PM
pausing is probably one of the hardest thing to do if not planned from the begining of the design phase! for now, your best bet is to move to another frame, show message, then get back to game frame!
pradvan
07-02-2009, 04:50 PM
If you got an onEnterFrame running your game, you could pause the game by turning off the onEnterFrame. Then when you want to resume the game, you can just turn it back on.
Let's say you have onEnterFrame on your map_mc movieclip:
map_mc.onEnterFrame = function(){
//code that does a bunch of stuff in the game
}
you can just say:
delete map_mc.onEnterFrame;
then to resume it, just give map_mc a new onEnterFrame function:
map_mc.onEnterFrame = function(){
//code that does a bunch of stuff in the game
}
Ciubhran
07-02-2009, 05:07 PM
Considering this is AS3, this is what you should do:
Most likely you have a looping function that updates the game, I call this function Loop, and I have it in the main section of the .fla.
stage.removeEventListener(Event.ENTER_FRAME, Loop);
This removes any updates to the game temporarily. That is if you have attached your main loop (Loop) to the stage, which I usually do.
Then just simply add another listener to do your other things, and remove that and re-add Loop when your other listener is done executing. Easily done by a boolean or something.
To sum up. Have two functions that do two different things.
One (Loop) that executes and does everything needed in your game.
The other (Intermission) that shows what the next level will be.
stage.addEventListener(Event.ENTER_FRAME, Intermission);
function Intermission(evt:Event) {
// position the text field where "Level X" shows up
// if the text field is in the position where the Intermission should end, then end it, and turn this event listener off, and turn back on Loop.
if(blah.y == 0) {
stage.removeEventListener(Event.ENTER_FRAME, Intermission);
stage.addEventListener(Event.ENTER_FRAME, Loop);
}
}
Kinda tired, but this is how I do it. Have differente ENTER_FRAME-functions for different things, and when one is done, or its execution is not desired, swap to the function that is desired.
kaptain kosher
07-05-2009, 09:00 PM
That or have a isPaused property in your document class, and at the beginning of ever "Loop" function or Act as I like to call it, have an if(MovieClip(root).getIsPaused() == false) if you don't want to mess with removing and adding listeners.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.