PDA

View Full Version : How to Pause / UnPause the Game???


CyanBlue
02-23-2002, 04:28 AM
Hi...

I made a little game and I want to put Pause/UnPause button...

I tried Jesse's code, but it didn't work well for me...

on (release) {
if (_root.pause == false) {
_root.stop()
} else {
_root.play()
}
}

When I tried the code, stop() looked like it just stopped the main timeline as it says _root.stop()... All other movieclips were still playing with that code... Does this mean that I have to go over all those little movieclips and tell them to stop??? Do I need to get the currentFrame for all those movieclips so that I can resume at that frame when the user pressed the UnPause button???
One more thing... the _root.play() somehow started my movie from the beginning... I have the main scene which is basically the introduction of the game, how to play and so on, and the second scene is the three frame long movie that does actual game play... The play() returned the timeline to the first frame of the main scene... I don't know why... Can someone help me how to put Pause/UnPause button for my game???

Thank you and have a nice weekend!!!

Jason

maccer
02-23-2002, 04:44 AM
that we be one way to do it..yet if there are lots of mc's then obviously that would be madness!!

i think you would need to create a movieclip.prototype function, that would set all obects of a movie clip instance to stop!!

will get back to ya on this one later...there are some examples of this in the functions library..you might find something there...

good luck for now

maccer
02-23-2002, 07:43 AM
on you first frame of your movie create the prototype function

MovieClip.prototype.stopAll= function () { if (goPlay && (play)) {gotoAndStop (_currentframe);}};

now on all the mc's that u want to pause place this:

onClipEvent (enterFrame) {
this.stopAll();
}

now for your pause btn use:

on (release) {
mc1.goPlay = false;
mc2.goPlay = false;
mc3.goPlay = false;
}

now for your play btn use:

on (release) {
mc1.goPlay = true;
mc2.goPlay = true;
mc3.goPlay = true;
}


there could be an easier way..but thats my best effort
keep me posted!!

CyanBlue
02-23-2002, 07:17 PM
Thank you, maccer...

I am fairly new to Flash, so bear with me... :)
I tried your suggestion with no succes due to lack of my knowledge on prototype... I am reading as much as I can right now about this prototype...

However, I have some problem understanding the use of this prototype in my program...
As for my understanding, prototype in Flash is creating a base object and the child objects of that object can inherit all the properties and functions of the parent object... Am I right??? It seems to me that this prototype is almost same as instanciating objects in Java if I may say...
The problem is that I do not have instanciated the prototype object in my movie at all, so how am I use the stolAll() function???

Basically I tried this... I changed the base name(?) of the prototype to Crane and put it to the first frame of the first scene...


Crane.prototype.stopAll= function () {
if (goPlay && (play)) {
trace("currentFrame = " + _currentFrame);
gotoAndStop (_currentframe);}};


and a couple of the moving movieclip throughtout the entire movie are Crane and Timer movieclips, in scene 2, so I've put the following on each movieclips...


onClipEvent (enterFrame) {
this.stopAll();
}


and on one of the empty movieclip that I have put all my scripts, I've put the following codes...


...
...
else if(Key.isDown(80))
{ // P
trace("P has been pressed for Pause");
_root.Paused = true;
Crane.goPlay = false;
_root.Crane.goPlay = false;
Timer.goPlay = false;
_root.Timer.goPlay = false;
}
else if(Key.isDown(85))
{ // U
if (_root.Paused)
{
trace("U has been pressed for UnPause");
Crane.goPlay = true;
_root.Crane.goPlay = true;
Timer.goPlay = true;
_root.Timer.goPlay = true;
_root.Paused = false;
}
}


On playtime...
I pressed 'P' key and 'U' key then I see following statements are working on the output window...
trace("P has been pressed for Pause");
trace("U has been pressed for UnPause");
I do not see either Crane or Timer stopping after the key press... as a matter of fact, I do not think stopAll() on each movieclips are working because my trace statement in the prototype is not showing anything at all...

I am still trying to figure it out myself...
A couple of tips from the masters would help me a lot... :)

Thank you and have a nice weekend...

Jason

maccer
02-23-2002, 10:18 PM
Basically I tried this... I changed the base name(?) of the prototype to Crane and put it to the first frame of the first scene...

thats the error!!

all mc's in a flash movie are infact an instance of the movieclip object...

so you would need to keep the code as

MovieClip.prototype.stopAll= function () { if (goPlay && (play)) {gotoAndStop (_currentframe);}};

then call the function on the desired mc's in your timeline with;


this.stopAll();
}


::::::::::im still not convinced this is the best way to do what u require but this will work:::::::::::

a better appraoch would be to create sopme kind of wrapper that would effect all mc's on the root level????

i will try to work something out...

CyanBlue
02-23-2002, 11:06 PM
Thank you, maccer... :)

Aha...
All the movieclips are the instances of the movieclip object... Gotcha!!! :)

Put play() at the end of your code and it is working as it is supposed to be... :)


MovieClip.prototype.stopAll= function () {
if (goPlay && (play)) {
gotoAndStop(_currentframe);}
else
play();};


What is the 'play' at the if statement though??? Is that some sort of reserved word??? It has to be because I see it in blue color in Flash, so it has to be.. I don't know...

Thank you and have a nice weekend...

Jason

ASMan
01-13-2006, 12:01 PM
You can redefedine existing prototipes in the master constructor. Yo don't need paste on(enterFrame) in each Movieclip of your proyect:

MovieClip.prototype.onEnterFrame = function () {
this.stopAll();
};

This work all right, so you only paste scripts at main movie (_root) first frame. 8)

Cota
01-13-2006, 12:48 PM
ASman...you do realize this thread is from 2002 dont you?

CyanBlue
01-14-2006, 09:00 PM
Ah... That's one of the first posts that I have made when I got into this AS.org... :D

Flash Gordon
01-14-2006, 09:03 PM
Ah... That's one of the first posts that I have made when I got into this AS.org... :D
In that case:

Howday and Welcome! :)

Kind of funny to hear CyanBlue say he is new to Flash.

CyanBlue
01-20-2006, 03:55 AM
Actually that's when I was really confused... I was migrating from Director to Flash at the time... It was a hectic... :D

Come to think of it, I don't think anybody said welcome to me when I got here... Hm... :p

Cota
01-20-2006, 05:55 AM
then let me be the first to welcome you to the forums...:p

Flash Gordon
01-20-2006, 05:59 AM
In that case:

Howday and Welcome! :)

Kind of funny to hear CyanBlue say he is new to Flash.
I beat ya.:p

Cota
01-20-2006, 06:06 AM
I'm slow but I get there...

CyanBlue
01-21-2006, 03:11 PM
Huh... Weird...
I did reply to Cota saying that Flash Gordon beat Cota on that... and I cannot find that reply... Was I dreaming or something??? Hm...

yker22
01-21-2006, 08:12 PM
CyanBlue:

Howdy and welcome to AS.org... :D

Hey, how do you become the master in that short time?

yker22
01-21-2006, 08:14 PM
I´m gonna follow your steps so I will be supermoderator in 2010 :D

Cota
01-21-2006, 08:26 PM
He made this thread in 2002..

yker22
01-21-2006, 10:40 PM
Yes Cota, I know, I´m reading the thread... so if CyanBlue starts here in 2002 and he is supermoderator now, me, that starts in 2005, maybe will be supermoderator too in 2010... :D

Cota
01-21-2006, 11:12 PM
He's been a super mode for over a year now..or at least that I remember.

maccer
01-24-2006, 02:00 PM
:eek: and just as shocking is me offering you help! while it also pains me to see my posts are still in the low hundreds :rolleyes:

But happy to see you sussed out movieclips....

Aha...
All the movieclips are the instances of the movieclip object... Gotcha!!! :)

And a slighty belated:

Welcome to AS.org!!! :)