A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: Stopping a MC's internal animation with a global Pause

  1. #21
    Junior Member
    Join Date
    Sep 2005
    Posts
    6
    Strille -
    That worked beautifully for me... i have movie clips made by 3 people with nested mcs and could never know the name of everything...

    I'll have to tweak my toggle to know when the user clicks another button to move on to revert to a 'pause' button - nbd...

    BUT... here's a good question... how to restart the playing without activating all the toggle buttons and drop down menus and other weird bells and whistles?

    I tweaked the script like so:
    Code:
    function startAll(instance) {
    	instance.play();
    	for (var n in instance) {
    		if (typeof(instance[n]) == "movieclip") {
    			arguments.callee(instance[n]);
    		}
    	}
    }
    and since, conveniently, everything i want to pause gets loaded into the same movie clip, I call the function like this:

    Code:
    startAll(movSpace);
    the only bummer is:
    when it restarts, some of the images and embeded movie clips disappear...

    odd odd odd...

    any ideas?

    thanks,
    Puck

  2. #22
    Junior Member
    Join Date
    Sep 2005
    Posts
    6
    it's almost as if instead of restarting on the frame it's on, it's either going back to where the most deeply embedded mc started or waiting for the _root of the embedded movie clip to trigger the next one...

    it freezes/pauses on the frame visible when the pause function is called, but visually, it doesn't necessarily restart there...

  3. #23
    Junior Member
    Join Date
    Jun 2006
    Posts
    12
    I know that this is alot easier then what this thread is about but I just need some simple help on pausing. I want the game to pause when I press start so
    I had this code:

    Code:
    function pauseCheck(){
    	if (Key.isDown (Key.ENTER )){
    		if (pause == false){
    			shipSpeed = 0;
    			laserSpeed = 0;
    			pause = true;
    		}
    		if (pause == true){
    			shipSpeed = 15;
    			laserSpeed = 15;
    			pause = false;
    		}
    	}
    }
    basicaly its supposeed to check if the game is paused or not from the variable pause. If its not it stops all the object moving and sets pause to true.
    Then if pushed again while paused it should make the objects move again.
    The problem is its not pausing at all. I know the problem has to be with the true and false but I dont know what. Any help would be nice.

  4. #24
    Feeling adventurous? T1ger's Avatar
    Join Date
    Mar 2004
    Posts
    850
    Code:
    function pauseCheck(){
    	if (Key.isDown (Key.ENTER )){
    		if (pause == false){
    			shipSpeed = 0;
    			laserSpeed = 0;
    			pause = true;
    		}
    		if (pause == true){ // at this point, pause is already set to true, two lines earlier. insert a else in front to avoid this.
    			shipSpeed = 15;
    			laserSpeed = 15;
    			pause = false;
    		}
    	}
    }
    
    function pauseCheck(){
    	if (Key.isDown (Key.ENTER )){
    		if (pause == false){
    			shipSpeed = 0;
    			laserSpeed = 0;
    			pause = true;
    		} else if (pause == true){
    			shipSpeed = 15;
    			laserSpeed = 15;
    			pause = false;
    		}
    	}
    }
    Edit: when I think about it a second time, this would make the pause blink when enter is down. Try this:

    Code:
    function pauseCheck(){
    	if (!Key.isDown (Key.ENTER )){
    		canpause = true;
    	} else {
    		if (pause == false){
    			shipSpeed = 0;
    			laserSpeed = 0;
    			pause = true;
    		} else if (pause == true){
    			shipSpeed = 15;
    			laserSpeed = 15;
    			pause = false;
    		}
    		canpause = false;
    	}
    }
    That should work. Now you pause/unpause only one time per enter-click.
    Last edited by T1ger; 06-22-2006 at 03:21 PM.
    I don't have a photograph, but you can have my footprints. They're upstairs in my socks.

  5. #25
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Using onEnterframe in each mc you want to pause is not an option imho, because having lots of onEnterFrame's is slow.
    I'm not sure why, but I don't like looping through the _root (or whatever container) either. Sometimes I don't want certain movieclips to keep playing (for instance, a neon sign or something).

    What I usually do, and I don't pretend that it's a better solution, is just add all movieclips that can be paused to an array, and loop through that. For some reason, to me it feels like a better design.

    If an mc has a non animated frame (for instance, a character standing still), I tend to make that two frame long, and add a gotoAndStop("standStill"); to the second frame. That way, if it gets started again by unpausing the game, it will automatically stop again, without having to have a "stopped" variable. Both ways are effective, just wanted to share another method. However, if your mc can stop at any frame, not just a few predefined idle frames, you still have to use the variable.

  6. #26
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    "Using onEnterframe in each mc you want to pause is not an option imho, because having lots of onEnterFrame's is slow."

    Totally, that's just vile.

    Every game should just use one onEnterFrame to run the mainloop, otherwise you're just making life ten times harder for yourself ( Don't get me wrong, I will drop the odd onEnterFrame onto the odd mc, but only when I can get away with it ).

    Squize.

  7. #27
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    true. but if that is the case you can always save the function pointer in an array and delete the onEnterFrame event. then restore it when you wanna start the game again.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  8. #28
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Yep. I just point the enterFrame to check for the pause key being pressed again ( ie, resuming the game ).
    Two birds, one stone and all that.

    Squize.

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