A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: pausing a game

  1. #1
    Senior Member
    Join Date
    Jan 2003
    Location
    Austin, TX
    Posts
    297

    pausing a game

    Hi,
    I have a tower defense game with enemies and towers that are nested inside movie clips upon movie clips, each with their own onEnterFrame and running their own code

    It's pretty much done, but... being a tower defense game that could take forever to play, it REALLY needs a pause button
    is there any easy way to just freeze everything without having to create a pause boolean inside all onEnterFrames and onMouseMoves, pausing all sounds, and then commanding all looping movie clips to pause, etc?

  2. #2
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    I use
    PHP Code:
    if(!root.paused){
    //actions

    Mc loops
    instead of playing mcs I only nextFrame() them till they reach certain frame gotoAndStop() them to loop

  3. #3
    It's true..I brought sexy back smith1302's Avatar
    Join Date
    Sep 2005
    Location
    here
    Posts
    343
    Nope there is no easy way. You just have to use the good old !pause and pause thing like never land said.
    Hey check out my arcade sites!
    Ninja Games | WW2 Games

  4. #4
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    huh? no easy way

    onEnterFrame = null;

    looks pretty easy to me

    as for pausing movie clips, that is what gets complicated, you have to use recursion and even then you must have a way to determine whether a paused movie clip was playing before you paused it, so it can resume animation. The easiest way I've found to do that is use 2 iterations for pausing:

    user requests pause
    create pause object
    run recursion through all movieclips on stage, through their children until no more clips are found.
    add these clips into pauseObject, record currentFrame property of all movieclips

    second iteration
    run through all objects in pauseObject, check pauseObject currentframe, if its different than the movieclips new frame, it must play again, so flag this.
    stop all movieclips
    null the enterFrame

    user resumes
    loop thorugh all objects in pauseObject
    if object needs play resume, do so
    clear pauseObject
    bring back enterFrame

    as for sounds, I would just stop all of them, no need to pause all sounds. Can't remeber the syntax in AS2, but something like: Sound.stopAll()
    Last edited by mr_malee; 02-10-2008 at 09:15 PM.
    lather yourself up with soap - soap arcade

  5. #5
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    Quote Originally Posted by bluekronos
    each with their own onEnterFrame and running their own code
    ,
    you´ll get a way better performance if you put all the code on the main timeline and run through a loop inside a onEnterFrame event instead of having multiple onEnterFrames.

    e.g
    PHP Code:
    function init(){
        
    towers = new Array();
        
    towers = [{x:15,y:64,type:1},{x:64,y:18,type:2},{x:2,y:8,type:2}];
        
        for (var 
    i=0;i<towers.length;i++){
            
    mc_world.attachMovie("tower","t"+i,i);
            
    mc_world["t"+i].gotoAndStop(towers[i].type);
        }
    }
    init();

    var 
    pause false;
    _root.onEnterFrame = function(){
        if (!
    pause){
            
            for (var 
    i=0;i<towers.length;i++){
                var 
    mc mc_world["t"+i];
                if (
    towers[i].type == 1){
                    
    //do code with mc tower type 1
                
    }else if(towers[i].type == 2){
                    
    //do code with mc tower type 2
                
    }
            }
        }

    plus your code structure will be much easier to change/ fix or extend because you dont need to change the code on multiuple movieClips. Hell putting code on MovieClips is flash5 style

  6. #6
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    now that we are talking about how to stop games, again

    can we talk about something I would like to implement to the stop

    I am asking if there is a way to have a print of every thing thats in screen,
    to stop only enterframes not animations, because honestly it's a pain in the a$$ unpause everything.

  7. #7
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    bitmapData, create a bitmapData the size of the stage, then draw() your world, _root or any clip where all game elements are stored into this bitmap.
    Code:
    var bmp = new BitmapData(Stage.width, Stage.height, true, 0)
    var mc = createEmptyMovieClip("pauseClip", depth)
    
    mc.attachBitmap(bmp)
    
    bmp.draw(myWorld)
    but it might look weird when switching back to game if animations are still playing
    lather yourself up with soap - soap arcade

  8. #8
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    Quote Originally Posted by Never_land:(
    now that we are talking about how to stop games, again

    can we talk about something I would like to implement to the stop

    I am asking if there is a way to have a print of every thing thats in screen,
    to stop only enterframes not animations, because honestly it's a pain in the a$$ unpause everything.
    PHP Code:
    for (var a in _root){
            if(
    typeof(eval(a)) == "movieclip"){
                
    delete eval(a).onEnterFrame;//will delete a mc.onEnterframe = function(){}; method
            
    }
        } 
    sadly mc.onEnterFrame =function(){}; and onClipEvent(enterFrame){}; are completely different things and this works only with the first one. As far as I know you can´t delete the later one aka the flash 5 style one.
    some other thread regarding that:
    http://www.actionscript.org/forums/s...threadid=24905

    Better get rid of that style anyway

  9. #9
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    render
    I got rid of that style ages ago I manage
    mc.onEnterFrame =function(){} with less enterframes as possible

    malee thnx for your code but it's not working

    Edit: trace (bmp) // undefined
    Last edited by Never_land:(; 02-11-2008 at 03:22 AM.

  10. #10
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    you have to import the bitmapData package:

    Code:
    import flash.display.BitmapData
    before you use it
    lather yourself up with soap - soap arcade

  11. #11
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Using draw(); like Mr.M suggested works a treat.

    A nice way to hide it ( When going back to the game from the pause mode ) is to cover the screen in some eye-candy when paused, so not just pause text but put a ghosted out box over the top, or put a blur on the paused bitmap, and then you can wipe back to the game and hide what you did.

    Nice.

    Squize.

  12. #12
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    Edit: yeah I see it in many console games.
    great idea mr malee can you send me a fla with your code, It's not working
    Last edited by Never_land:(; 02-11-2008 at 07:59 PM.

  13. #13
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    CS3 format
    Last edited by mr_malee; 07-16-2008 at 10:17 AM.
    lather yourself up with soap - soap arcade

  14. #14
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    I use flash8

  15. #15
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    heer you go
    Last edited by mr_malee; 07-16-2008 at 10:17 AM.
    lather yourself up with soap - soap arcade

  16. #16
    talk to the hand! Never_land:('s Avatar
    Join Date
    Nov 2007
    Location
    your mother's bedroom
    Posts
    490
    woooooohoooo thanks mr malee.
    owe you one

  17. #17
    Junior Member
    Join Date
    Mar 2008
    Posts
    2
    i found a component called pause component. it can pause/resume every nested onEnterFrames, movieclips, buttons, mouse & key listener.
    find it at
    http://www.flashcomponents.net/autho...binkhalid.html

    this component cost USD15. but it still do wonder for my game.

  18. #18
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,378
    I don't understand malee, why two iterations? Why not just give the movieclips an isPlaying boolean member, and set it to true or false when starting/stopping it? Then you'd only need one iteration and just check if (mc.isPlayer) {}; or is there something I'm missing?
    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

  19. #19
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    Quote Originally Posted by sasuke82
    http://www.flashcomponents.net/autho...binkhalid.html
    this component cost USD15. but it still do wonder for my game.
    that is soooo sad- because basicly all you need are 2-3 lines of code.

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