Jump to content
GreenSock

lunelson@gmail.com

Queueing .ticker callbacks before visual updates?

Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I'm looking at the documentation for TimelineLite.ticker and I'm curious: is it possible to set a priority to the event listener, such that it would be run before tweens and timelines update visually? I'm thinking of, for example, touching the DOM in order to take measurements that might affect a progress parameter, to which timelines refer. Basically read/write or "measure/mutate" batching. 

 

addEventListener(type, callback, scope, useParam, priority)

 

Obviously, I can separate this in other ways but let's assume I need to read this value from the DOM just before the tweens and timelines update

Link to comment
Share on other sites

Thanks, yes I read that too; but was still wondering what exactly "update" meant in this context:

 

Quote

The object that dispatches a "tick" event each time the engine updates

 

...is this after all values have been internally computed, but nothing yet drawn? Or after drawing updates have been done?

Link to comment
Share on other sites

I should have read your post a bit more slowly... I just realised I misread your first sentence as: "I'm looking for..." rather than "I'm looking at...". Apologies for that. :oops:

 

I personally am can't say for sure but, my understanding of the way requestAnimationFrame and GSAP works is that, the ticker will dispatch its events after everything is computed and then, the rendering occurs. The browser is the one scheduling the draws, GSAP only updates whatever numbers its working with.

 

But, don't listen to me. I can't even read correctly... Mr. @GreenSock or @Carl should be able to give you a more definitive answer.

Link to comment
Share on other sites

Yep, if you set the priority to 1 (or above), it should call that function BEFORE the engine updates all the tween values because the internal ticker has a priority of 0. 

 

Enjoy!

  • Like 2
Link to comment
Share on other sites

Thanks Jack! I'll go and think about this some more... I'm guessing, that if I called an update method on a Tween during a tick callback with a priority > 1, that update would happen on the next tick, not on the same one, right?

Link to comment
Share on other sites

Hm, I don't quite understand the question. Got a quick demo? What "update" method? 

Link to comment
Share on other sites

Hm. Well, if you set the progress(), that happens immediately.

Link to comment
Share on other sites

Aha! So, on the same tick? I figured it would be scheduled via requestAnimationFrame, and thus happen on the next tick, like when you call requestAnimationFrame from within a requestAnimationFrame handler and it gets scheduled on the next frame...

Link to comment
Share on other sites

Yep, it happens immediately. Otherwise, it'd be pretty awkward if you had code right after the progress() call that depended on the values being set. See what I mean? 

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