Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
dominate

Is it possible to queue tweens with TweenLite?

Recommended Posts

What I want to achieve is:

 

- Create a tween on myobj and play, let say x:"+=200"

- Some other time another "additive" tween may be created, ie., x:"+=200" more!.

- So, as a result myobj should go x:"+=400".

 

- To do that, second tween should wait the first one, and then run when it finishes. Moreover, if more tweens come later, they should wait all the previous ones.

- Please note that it is unknown how many tweens would exist. They come dynamically.

 

My question is if it is possible to queue like this using TweenLite, or I need TimelineLite.

 

Thanks.

Link to comment
Share on other sites

Hi dominate :)

 

it's better to use Timeline , you can add tweens to tl and the new tweens will add at the end of timeline , however if you want to just load TweenLite , there's " onComplete " callback for tweens : http://greensock.com/docs/#/HTML5/GSAP/TweenLite/eventCallback/

 

you can define onComplete callback with these ways :

var myAnimation = TweenLite.to(obj,1,{...});
myAnimation.eventCallback("onComplete", myFunction);

or

TweenLite.to(obj,1,{... , onComplete : myFunction });
  • Like 2
Link to comment
Share on other sites

Like Diaco said, you can do that with callbacks. Here's an example of that I made for a similar question.

See the Pen xGMYmW?editors=001 by osublake (@osublake) on CodePen

 

You could also use promises. Here's a promise wrapper for GSAP. It uses the Bluebird promise library.

https://github.com/mattdesl/gsap-promise

  • Like 4
Link to comment
Share on other sites

Thanks for replies. So it is better to use Timeline, since if not it must be necessary to maintain a map of tweens.

Link to comment
Share on other sites

Whatever works best for you situation. It's hard to say if one way is better than the other. A map is nice because you can reorder or remove them fairly easily. Notice how in the example I linked to that it was pulling tweens from the front instead of the back. That would be much harder to do with a timeline.

 

Promises are also nice because you can cancel them and even setup an alternate animation if it gets canceled.

  • Like 1
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.
×