Jump to content
GreenSock

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

TimelineMax addCallback bug

Recommended Posts

timeline.addCallback(function():void

{

trace(timeline.time());

}, 0);

 

expected: 0

output: 1.1 (or any random number depending on the timeline duration)

 

I know there are events, but this should work too

Link to comment
Share on other sites

another bug:

 

the duration of the timeline is a small number like 0.16

I want to add a callback at the center of the timeline on 0.08

The callback is called near the end

Link to comment
Share on other sites

Neither of these are bugs, although I can understand why it might seem like they are - let me explain...

 

All computer animation is iterative in a sense - things get updated a certain number of times per second, but even that is somewhat unpredictable. For example, if the browser or Flash Player is busy rendering some huge graphic, your normal 60fps animation may run at 2fps for a brief time until the computer has the resources to throw at it. If you do a setTimeout() and tell the computer you want it to call a function in exactly 1000ms, it may end up being 1001ms or even 3000ms if there was some huge CPU-melting calculation that was happening inbetween.

 

Think of a TimelineMax as a scheduling mechanism where you place tweens, callbacks, etc. The time (position of the playhead) gets updated at a certain frequency which is typically dictated by your swf's fps, but of course that can change at runtime based on processor load.

 

Let's take an extreme example to make a point: let's say the playhead is currently at exactly 0.5 seconds on the timeline and you placed a callback to run exactly 0.1 seconds from now (which is at the 0.6-second position on the timeline). Great. But in the mean time, there's a massive vector graphic that Flash is having to scale and render on the screen which is extremely CPU-intensive, so by the time it takes a breath from doing that work, 0.25 seconds has elapsed. So when your TimelineMax updates its time, it's actually at 0.75 seconds now. It notices that your callback was inbetween the previous time (0.5) and the new time (0.75), so it triggers it immediately. But if you trace() the timeline's time, it's 0.75. I'm sure you're thinking "WHAT? I said my callback was supposed to be called at EXACTLY 0.6 seconds, so there must be a bug in this crappy software." :)

 

Not so.

 

The only alternative would be to use a frames-based TimelineMax where all the times are based on frames. That way, ever time a render occurs, it increments the frame counter. You could be 100% sure that every single frame will get hit, but the [big] down side is that if the CPU bogs down, your animations will sl...o..w.....d...ow..n. The durations would get stretched out. Most animators don't want that - they'd much rather that the time be honored rather than frame renders. That's the default in GSAP, but you can certainly use frames if you prefer. Just use the "useFrames:true" in the vars parameter of your TimelineMax constructor.

 

Does that clear things up?

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