|
-
Senior Member
Pausing
I know this questtion has bin asked before because i searched it but i didnt understand how it all works.
How can i pause my game and then unpause it and every thing continue from were it stoped?
I cant get my head around it, i have 1large block of code in a controle MC and a little bit of code in a few other MC's.
92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!
-
Senior Member
the way i code, is that i have a controller function
Code:
controller = function() {
timer()
player()
enemies()
}
something like that... this one enterframe loop controls everything.
to start it....
onEnterFrame = controller;
to stop it...
delete onEnterframe;
to start it again...
onEnterFrame = controller;
so therefore pausing is extremely easy. If you need to pause movie clip animation strille has posted a nice function to do this recently.
-
Senior Member
mbenney has suggested the best way to do this, it is also close to how it would be achieved professionaly... personally i would have a pause function that is ran onEnterFrame instead of just deleting the loop, you can then check for key presses to unpause the game again.
This subject has been brought up many times, try searching for more examples.
fracture2 - the sequel
fracture - retro shooter
blog - games, design and the rest
"2D is a format, not a limitation" -Luis Barriga
-
M.D.
Tried Strille's pausing function on Flash 8. Doesn't work. Copied and pasted it, shows the following error.
"256 levels of recursion were exceeded in one action list.
This is probably an infinite loop.
Further execution of actions has been disabled in this movie."
Any ideas on how to detect whether or not to continue the for in loop search.
Strille's code:
code:
function stopAllMovies(instance) {
instance.stop();
for (var n in instance) {
if (typeof (instance[n]) == "movieclip") {
arguments.callee(instance[n]);
}
}
}
stopAllMovies(_root);
-
Code:
gameplay = true;
if (gameplay) {
// gameworks
// all code in here
// the infamous pause below
if (Key.isDown(Key.SPACE)) {
gameplay = false;
}
}
-
Hype over content...
It's much better using the one enterFrame mainloop approach rather than constantly checking a flag to see if a game is paused. It means [ Checking the flag way ] you're running a conditional check every frame which is only ever going to be needed 0.1% of the total time the game's running.
To stop the mc's animating, I usually have all active sprites stored away somewhere, so just run a loop through them telling them to stop. Stops the 256 error if there's just too much content whizzing around.
Squize.
-
Senior Member
With Mbennys way i would have somthing like
onEnterFrame = function() {
controller}
controller = function() {
//This area Contains all my code?
}
92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!
-
Senior Member
You would use:
code:
controller=function(){
//stuff
}
onEnterFrame = controller;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|