How to pause a game?
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 36

Thread: How to pause a game?

  1. #1
    Game Player - Developer scheletro's Avatar
    Join Date
    Mar 2005
    Location
    México living in Barcelona
    Posts
    1,119

    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"

  2. #2
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    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

  3. #3
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    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 )

  4. #4
    Game Player - Developer scheletro's Avatar
    Join Date
    Mar 2005
    Location
    México living in Barcelona
    Posts
    1,119
    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"

  5. #5
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    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

  6. #6
    Zombie Coder EvilKris's Avatar
    Join Date
    Jun 2006
    Location
    Fukuoka, Japan.
    Posts
    796
    Make sure you've only got the one onEnterFrame though.
    Better just to have one boolean IMO.

    If(!pause)
    {
    do everything
    }

  7. #7
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,472
    ^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."

  8. #8
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,182
    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);

  9. #9
    Game Player - Developer scheletro's Avatar
    Join Date
    Mar 2005
    Location
    México living in Barcelona
    Posts
    1,119
    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"

  10. #10
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    I always put a screen on top of everything, stop the codes and _visible false the duplicated Mcs

  11. #11
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    Quote 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.
    lather yourself up with soap - soap arcade

  12. #12
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    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

  13. #13
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,140
    this handsome man doesn't believe in most situations
    lather yourself up with soap - soap arcade

  14. #14
    Junior Member
    Join Date
    Nov 2007
    Posts
    7
    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

  15. #15
    Game Player - Developer scheletro's Avatar
    Join Date
    Mar 2005
    Location
    México living in Barcelona
    Posts
    1,119
    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"

  16. #16
    Junior Member
    Join Date
    May 2008
    Posts
    1
    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?

  17. #17
    Junior Member
    Join Date
    Mar 2008
    Posts
    2
    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

  18. #18
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    Quote Originally Posted by Spammer
    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
    from that link:
    Quote 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.

  19. #19
    Game Player - Developer scheletro's Avatar
    Join Date
    Mar 2005
    Location
    México living in Barcelona
    Posts
    1,119
    15 ???

    Good look

    I prefer to do it my way


    "I love to make them as I love to play them"

  20. #20
    Junior Member
    Join Date
    Apr 2008
    Posts
    16
    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
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com