Jump to content
Search Community

onUpdate

mimeartist test
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

Is there a way to set the onUpdate when doing a Tween to be less frequent... basically I'm doing a very slow slideshow of images that pan past the screen and it calculates which one is most on screen so it can display the correct caption...


 


the scroll is super slow so any extra processing power would be nice to keep it as buttery smooth as possible... so really I only want the onUpdate to be called every second for example... Is there anything like that built in? Before I  reinvent the wheel :)


  • Like 1
Link to comment
Share on other sites

Hi mimeartist  :)

 

you can try something like this :

 

var ticker = new com.greensock.Ticker(1); // tick once per second

ticker.addEventListener("tick", render);
                  
function render(){ console.log('hi') }; // render is your function to call and can be whatever you want

TweenMax.to('.ball', 30 ,{x:200 ,
  onStart:function(){ ticker.addEventListener("tick", render); },
  onComplete:function(){ TweenLite.delayedCall(0.01,function(){ ticker.removeEventListener("tick", render) } ) } 
});
  • Like 4
Link to comment
Share on other sites

yep it's one of the GSAP engine options .

 

and onComplete will remove listener but if you kill before tween complete , you should to remove that with this :

ticker.removeEventListener("tick", render); 

and another way is this ( without addListener ) :

var tick = 0;
TweenMax.to('.ball', 30 ,{x:200 ,
  onStart : function(){ tick = 0 },
  onUpdate : function(){
    tick++ ;
    if ( tick%60 == 0 ){ // your function call or whatever }
  }
});
  • 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.
×
×
  • Create New...