A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Pausing

  1. #1
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874

    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!

  2. #2
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744
    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.

  3. #3
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    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

  4. #4
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    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);

    lather yourself up with soap - soap arcade

  5. #5
    better than chuck norris
    Join Date
    Jun 2004
    Location
    West Coast of Michigan
    Posts
    667
    Code:
    gameplay = true;
    if (gameplay) {
         // gameworks
         // all code in here
         // the infamous pause below
         if (Key.isDown(Key.SPACE)) {
              gameplay = false;
         }
    }

  6. #6
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    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.

  7. #7
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    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!

  8. #8
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center