Jump to content
Search Community

Replacing the updateAll function

luke test
Moderator Tag

Recommended Posts

Hi there. I'm am making a game that requires a pause function, this would need all animations to stop so it is visually paused.

 

I'm wondering if it is possible to add a simple "if paused, return" line before the updateAll function is called. Does anyone have any advice on the best way to go about this or an experience with a similar problem?

Link to comment
Share on other sites

G'day mate,

 

Here's what I'd probably do. This is just a rough example but when your creating your tweens, I'd probably push them all into an array. When you have that array, you have all tweens that are currently in your game. With a simple toggle pause function you could loop through all your tweens and either pause or resume them. Like I said it's really rough but it should do what your looking for.

 

	private var aTweens:Array;

	public function main() 
	{
		aTweens = new Array();

		var t1:TweenMax = new TweenMax(obj1, 1, { x:100, y:100 } );
		var t2:TweenMax = new TweenMax(obj2, 1, { x:200, y:250 } );

		aTweens.push(t1)
		aTweens.push(t2);

		//To pause all tweens
		togglePauseTweens(true)

		//To resume all tweens
		togglePauseTweens(false)

	}

	private function togglePauseTweens(bPaused:Boolean):void 
	{
		for (var i:int = 0; i < aTweens.length; i++) 
		{
			var item:TweenMax = aTweens[i];
			if (bPaused)
			{
				item.pause();
			} else
			{
				item.resume();
			}

		}
	}

Link to comment
Share on other sites

There are two pretty easy solutions:

 

1) Use TweenMax so that you can call its TweenMax.pauseAll() and TweenMax.resumeAll() methods

 

-OR-

 

2) Just put your tweens into a TimelineLite or TimelineMax instance so that you can pause() or resume() them anytime. Heck, you could also alter the timeScale to make them all run faster or slower. Or reverse(). Whatever. This technique also allows you to segregate your tweens into groups so that you have more control. See http://www.greensock.com/learning/

Link to comment
Share on other sites

Thanks for both of your replies, I have already wrote something as Zync suggested (cheers buddy!) but it will take a while to put that code in.

 

I think i'll look into putting everything into a Timeline or just using TweenMax, i'm currently using TweenLite for pretty much everything. I wasn't aware that TweenMax had those functions, a bit of an oversight there!

 

Again, thank you both for the speedy and helpful responses.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...