Jump to content
GreenSock

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

Performance of two timeline rather then one.

Recommended Posts

I find it easier sometimes to create two timelines rather then one for complex animations. I know I can make one timeline out of it, but my head is spinning as it is. 

 

Wondering if there is a performance hit of any sort using two timeline instead of one. I will have two object moving at once regardless. 

 

Thanks

Link to post
Share on other sites

If your animations are getting complex and hard to manage, it sounds like the perfect time to start nesting your animations in a master timeline. You'll find it easier to work on small segments and move individual pieces around a master timeline. The code looks like this:

function part1() {
var tl = new TimelineMax();
tl.to( element, 1, {  } );
return tl;
}

function part2() {
var tl = new TimelineMax();
tl.to( element, 1, {  } );
return tl;
}

var masterTimeline = new TimelineMax();
 masterTimeline
 .add( part1() )
 .add( part2() );

Here's a simple CodePen with the basic mechanics and a position parameter added to the nested timelines.

 

See the Pen ZLxdXz by PointC (@PointC) on CodePen

 

Hopefully that helps.

 

Happy tweening.

:)

  • Like 4
Link to post
Share on other sites

Right, so there is a performance difference between two timelines vs one?

Link to post
Share on other sites

Nah, performance-wise it's almost the same. I guess technically it's an extra function call if you nest it, but you'd never notice any real-world difference unless maybe you're nesting things hundreds of levels deep and there are thousands and thousands of simultaneous tweens. Actually, in some cases nesting can actually improve performance. 

 

Happy tweening!

  • Like 4
Link to post
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.

×