Be a Supporter!

Pause button in a Flash Game?

  • 745 Views
  • 12 Replies
New Topic Respond to this Topic
MoArman
MoArman
  • Member since: Mar. 19, 2011
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Pause button in a Flash Game? 2012-10-15 15:10:34 Reply

Hey guys my first topic post here.
I'm making a flash game at the moment and I was wondering how I could have a "pause" button in the game, so the enter frame functions of some mcs would be temporarily disabled. Any ideas on how I would do this?

ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to Pause button in a Flash Game? 2012-10-15 15:18:42 Reply

At 10/15/12 03:10 PM, MoArman wrote: Hey guys my first topic post here.
I'm making a flash game at the moment and I was wondering how I could have a "pause" button in the game, so the enter frame functions of some mcs would be temporarily disabled. Any ideas on how I would do this?

General answer is to disable everything that is running that you don't want to run anymore. You are the only one who knows what's running and what you don't want to run when "pause" is triggered.


You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Pause button in a Flash Game? 2012-10-15 15:19:32 Reply

At 10/15/12 03:10 PM, MoArman wrote: Hey guys my first topic post here.
I'm making a flash game at the moment and I was wondering how I could have a "pause" button in the game, so the enter frame functions of some mcs would be temporarily disabled. Any ideas on how I would do this?

welcome :)

your post doesn't give very much information. The first thing i'm going to ask about is what language you're making your game in. AS2 or AS3?


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
CharlieSimpson
CharlieSimpson
  • Member since: Sep. 23, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Pause button in a Flash Game? 2012-10-15 15:20:18 Reply

At 10/15/12 03:10 PM, MoArman wrote: Hey guys my first topic post here.
I'm making a flash game at the moment and I was wondering how I could have a "pause" button in the game, so the enter frame functions of some mcs would be temporarily disabled. Any ideas on how I would do this?

Heya,

stage.addEventListener(Evenet.ENTER_FRAME, onFrame, false, 0, true);

when you want to pause-

stage.removeEventListener(onFrame);

unpause-

stage.addEventListener(Evenet.ENTER_FRAME, onFrame, false, 0, true);

:D

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Pause button in a Flash Game? 2012-10-15 15:28:55 Reply

At 10/15/12 03:20 PM, CharlieSimpson wrote: stage.removeEventListener(onFrame);

That depends on a lot of variables.
1) That he's using AS3
2) That he's putting his entire game loop in one function
3) That he's not using some external stuff like TweenLite
4) That he doesn't have other enterFrame listeners elsewhere.

besides, there's a better way to pause with AS3, anyway.
Just set the framerate to 0.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Pause button in a Flash Game? 2012-10-15 15:32:00 Reply

At 10/15/12 03:20 PM, CharlieSimpson wrote: stage.addEventListener(Evenet.ENTER_FRAME, onFrame, false, 0, true);

ieee! You shouldn't be using "stage.", anyway. That's like using "_root." everywhere in AS2.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
MoArman
MoArman
  • Member since: Mar. 19, 2011
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Pause button in a Flash Game? 2012-10-15 15:42:00 Reply

as2

CharlieSimpson
CharlieSimpson
  • Member since: Sep. 23, 2012
  • Offline.
Forum Stats
Member
Level 01
Blank Slate
Response to Pause button in a Flash Game? 2012-10-15 15:47:12 Reply

At 10/15/12 03:28 PM, egg82 wrote:
At 10/15/12 03:20 PM, CharlieSimpson wrote: stage.removeEventListener(onFrame);
That depends on a lot of variables.
1) That he's using AS3
2) That he's putting his entire game loop in one function
3) That he's not using some external stuff like TweenLite
4) That he doesn't have other enterFrame listeners elsewhere.

besides, there's a better way to pause with AS3, anyway.
Just set the framerate to 0.

hehe, zzzzzzzzz....... he asked a simple question I gave a simple answer I said "stage" because I dont know which variables/classes he's using and a universally known reference is "stage".... of course one can change the reference of the listnener. If anyones using more than one ENTER_FRAME event...they shouldn't, if anyone ever uses a tween....they shouldn't. The last one...setting your frame rate to zero will make everything not work, when you set your frame rate to 0 it actually sets it to like 0.001 or something which is not pausing a game as the game will still be running, just very slowly and if you leave for an extended period of time can cause problems.

:D

MoArman
MoArman
  • Member since: Mar. 19, 2011
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Pause button in a Flash Game? 2012-10-15 15:47:37 Reply

At 10/15/12 03:19 PM, egg82 wrote:
welcome :)

your post doesn't give very much information. The first thing i'm going to ask about is what language you're making your game in. AS2 or AS3?

I'm using AS2.

milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Pause button in a Flash Game? 2012-10-15 16:06:50 Reply

At 10/15/12 03:47 PM, MoArman wrote: I'm using AS2.
onEnterFrame = null;

You should really learn As3, so you can translate the advices and snippets you receive into your outdated language.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Pause button in a Flash Game? 2012-10-15 16:32:42 Reply

At 10/15/12 03:47 PM, CharlieSimpson wrote: hehe, zzzzzzzzz....... he asked a simple question I gave a simple answer I said "stage" because I dont know which variables/classes he's using and a universally known reference is "stage"....

you shouldn't ever have to use "stage." or "_root." - that's my point.

of course one can change the reference of the listnener. If anyones using more than one ENTER_FRAME event...they shouldn't,

I see a few reasons to use more than one ENTER_FRAME listener. It's not common to do so, but it has its uses nontheless.

if anyone ever uses a tween....they shouldn't.

Um... What?

The last one...setting your frame rate to zero will make everything not work, when you set your frame rate to 0 it actually sets it to like 0.001 or something which is not pausing a game as the game will still be running, just very slowly and if you leave for an extended period of time can cause problems.

may or may not happen, but that plus a big "unpause" button covering the screen is more universal than removing an event listener.

anyway, in order to truly put your game on pause you're going to have to add a boolean to your classes and check that boolean on every event fire.
Or remove the events and put them back in place. Your call, really.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Pause button in a Flash Game? 2012-10-15 16:35:43 Reply

At 10/15/12 04:32 PM, egg82 wrote: you shouldn't ever have to use "stage." or "_root." - that's my point.

I suppose I shouldn't say "ever" (in the case of stage.frameRate and adding keyboard event listeners, etc) but you get what i'm saying.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Pause button in a Flash Game? 2012-10-16 18:19:50 Reply

Accessing parents from children is a bad idea, this include nearly all references to stage or _root, as for a pause button, long story short, unless you have been putting all your code very neatly on the timeline or in classes then it's not going to be possible.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature