-
Game Player - Developer
How to pause a game?
Hi
I want to add a pause button to my games
I understand ill need a different function to pause all the animations and another to pause the script, but I know there is a way to stop everything, I know how to stop animations, but the script?
I want the same effect as when you are playing a game and to pause click right button of the mouse to stop everything, so there is a function to stop everything on the flash
How can I do that?
Any ideas?
"I love to make them as I love to play them"
-
Pumpkin Carving 2008
First and foremost, there is no function that will pause flash. The best way to pause a game is by implementing a game 'state machine'. This basically means that everything in your game is running through a function on the onEnterFrame. When you want to pause the game, you simply set onEnterFrame to null. Any animations might still play until their end, but no code will run and the game will appear to stop.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Yes we can
yup, in older flash versions it could be as easy as
run game:
onEnterFrame=mainGameLoopFn
pause game:
onEnterFrame=gamePausedFn
(in case you want to run some code while the game is paused, otherwise just null the enterframe as our dude in the prison said )
-
Game Player - Developer
Well, then I have to apply that on my next game
How do I set my onEnterFrame to null?
"I love to make them as I love to play them"
-
Pumpkin Carving 2008
ummm..... onEnterFrame = null;
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Zombie Coder
Make sure you've only got the one onEnterFrame though.
Better just to have one boolean IMO.
If(!pause)
{
do everything
}
-
Wait- what now?
^thats what I do
"I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."
-
SaphuA
Just for the input, here's how to stop all animations in your movie using a simple recursive function.
Code:
function StopAnimate(target) {
for (var a in target) {
if (typeof (target[a]) == "movieclip") {
target[a].stop();
StopAnimate(target[a]);
}
}
}
StopAnimate(this);
-
Game Player - Developer
Thanks for your help guys
Now I have good resources to make the "pause" button, thanks !!!
"I love to make them as I love to play them"
-
talk to the hand!
I always put a screen on top of everything, stop the codes and _visible false the duplicated Mcs
-
M.D.
Originally Posted by SaphuA
Just for the input, here's how to stop all animations in your movie using a simple recursive function.
Code:
function StopAnimate(target) {
for (var a in target) {
if (typeof (target[a]) == "movieclip") {
target[a].stop();
StopAnimate(target[a]);
}
}
}
StopAnimate(this);
All well and good until you have to unpause. Pain in the ass trying to figure out if a movieclip was playing before you paused.
-
Pumpkin Carving 2008
Most situations I'd think if the playhead weren't on frame 1 of the animation, then it was probably playing.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
M.D.
this handsome man doesn't believe in most situations
-
Hi I think I'm doing the same thing as you.
I'm making a game and want it to pause when I press P and unpause when I press U.
This is the code on my background movieclip:
Code:
if (Key.isDown(80)) {
trace("P has been pressed for Pause");
_root.Paused = true;
MovieClip.goPlay = false;
_root.MovieClip.goPlay = false;
this.stopAll();
}
if (Key.isDown(85)) {
if (_root.Paused)
{
trace("U has been pressed for UnPause");
MovieClip.goPlay = true;
_root.MovieClip.goPlay = true;
Timer.goPlay = true;
_root.Timer.goPlay = true;
_root.Paused = false;
}
this.stopAll();
}
This is the code on my control frame:
Code:
MovieClip.prototype.stopAll= function () {
if (goPlay && (play)) {
gotoAndStop(_currentframe);}
else
play();};
But only problem is, it doesn't work... Does anyone have any ideas?
I tried that null thing but didn't get any results. I'm using CS3 but actionscript 2.0.
Regards,
Josh
-
Game Player - Developer
I used both systems, the one for pausing the script and the one for pusing the animation
So now I will pause all my games
Thanks for everything guys and here is the game I releassed
game thread
"I love to make them as I love to play them"
-
Hey I know this is a big ask! but I was wondering if you could possibly post the .fla file somewhere? I'm trying to work out how to pause my game as well and I'm pretty amateur in flash, but I'd be able to work it out easily if I could look at how you set it up. pease?
-
hai guyz, i just create a component that can pause almost everything in swf. you can find it at
http://www.flashcomponents.net/compo...component.html
-
Originally Posted by Spammer
from that link:
Originally Posted by http://www.flashcomponents.net/component/flash_pause_component.html
...Price : $15
... oops I guess you forgot to mention that- and I was already thinking you were insulting people here with a component because they can´t write actionscript themselves.
-
Game Player - Developer
15 ???
Good look
I prefer to do it my way
"I love to make them as I love to play them"
-
If(!pause)
{
do everything
}
Can you elaborate on the above?
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
|