Jump to content
GreenSock

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

How to detect a change in TimelineMax duration

Recommended Posts

Hi all,

 

I need to do some calculations after timeline (TimelineMax) duration changes.  I take it can change because of number of things, i.e. adding or removing tweens, changing repeat values, etc. etc. There are a number of components in my application that could cause the change, so I'm looking for a method to somehow intercept or detect the change... hopefully there's a callback or something that I've just missed in the docs...:)

 

-Mika

Link to comment
Share on other sites

Sorry, there isn't such a callback in place. We try to keep the API as fast and lean as possible. Like you noted there are many ways that a timeline's duration can change without directly going through the timeline, like when you change the duration of a child. This would probably mean that every time you change some property of tween the engine would have to check if that tween had a parent timeline and then assess whether that change affected the duration of the parent and then fire off an event.

I can definitely see how such a callback would help you and maybe there is a possible solution.

 


I'm not entirely sure of the impact on the entire engine, but I'm sure @GreenSock
will weigh in if there is more to add.  We always appreciate suggestions for improving the engine!

 

 

 

 

 

  • Like 2
Link to comment
Share on other sites

Yeah, that type of feature could cause a lot of performance problems. Imagine someone does a loop through 1000 elements, adding a tween for each to a timeline...a callback like your suggesting could fire 1000 times in that loop alone. Yikes! And as @Carl indicated, there are many ways a duration could change (children, children's children, etc.), so it'd have to bubble up properly...another potential performance issue. I just don't think something like this belongs in the API. If I were you, I'd probably just structure my code accordingly so that I either funnel timeline changes through a particular function that runs this check for me, or use an onUpdate on that timeline that watches for its own duration changes - that way, things would be batched since the onUpdate is typically only called once per tick. Of course that'd be delayed by one frame, so in the above example with 1000 loops, you wouldn't know about the duration change until the next tick/update. I suspect that'd suffice for most cases, though. If you need it on the same tick, I suppose you could batch it by TweenLite.ticker.addEventListener("tick", yourFunction). 

 

In short, there are solutions for this that you could implement via your own code structure rather than relying on an internal callback in GSAP. I realize that's not what you were hoping to hear, but we really, REALLY try to keep performance optimized in GSAP since animation is the single most UX-sensitive part of an app. 

 

Thanks for being a "Business Green" member!

  • Like 3
Link to comment
Share on other sites

 

Quote

In short, there are solutions for this that you could implement via your own code structure rather than relying on an internal callback in GSAP. I realize that's not what you were hoping to hear, but we really, REALLY try to keep performance optimized in GSAP since animation is the single most UX-sensitive part of an app. 

 

Yes, well, the disappointment is easy to bear. It'll be simple enough for me to use onUpdate, but I just wanted to check if there was a better way. Thanks for your help!

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.
×