Jump to content
GreenSock

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

Is it possible to control the rate of onUpdate

Recommended Posts

I was curious if can set the rate that a specific tween fires onUpdate. Basically, I want to simulate a lower frame rate for a tween that is using onUpdate. I've seen that the TweenLite.ticker.fps(10) could work, but this seems to control the rate at all the tweens, and not just one specific tween.

 

TweenMax.to("#lowFps", 3, {
  onUpdate: () => animate()
})

 

In my Codepen example, I was hoping to have the top Tween smooth, and bottom one look like it's low fps. However, changing the ticker of course effects both.

See the Pen ydOvQm by anon (@anon) on CodePen

Link to comment
Share on other sites

@Fakebook,

 

I think your best bet would be to add a throttle function inside your `update` function (rather than trying to throttle GSAP's built in onUpdate or tick). If you're just going for the visual effect, @Visual-Q's solution is money!

  • Like 3
Link to comment
Share on other sites

2 hours ago, Visual-Q said:

Note sure about whether you can throttle a callback in that way,  but you could probably make your tween behave the way you want with stepped Ease.

 

https://greensock.com/docs/Easing/SteppedEase

 

 

 

 

 

 

 

@Visual-Q This is definitely a great idea, but it appears that using stepped easing doesn't effect the onUpdate rate. I'm guessing it might be best to throttle inside my function as @elegantseagulls mentioned.

Link to comment
Share on other sites

I'd go with a steppedEase. You can even use a stagger and cycle if you like.

 

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

 

Happy tweening.

  • Like 4
Link to comment
Share on other sites

4 minutes ago, PointC said:

I'd go with a steppedEase. You can even use a stagger and cycle if you like.

 

 

Wow, never occured to me to pass an ease to cycle. Could do a lot of really cool stuff with that.

 

11 minutes ago, Fakebook said:

but it appears that using stepped easing doesn't effect the onUpdate rate.

 

As @PointC demonstrated the onUpdate isn't needed unless of course you intend to do more with the callback function. 

  • Like 1
Link to comment
Share on other sites

I like the SteppedEase approach, but if you really need to limit the entire update of a tween to a certain FPS, you could do something like this: 

 

See the Pen 2b4554531b20a9876dac381beea741e2 by GreenSock (@GreenSock) on CodePen

 

Here's the utility function I whipped together, so you can just pass a tween/timeline instance in, along with the desired FPS, and it'll do it all for you: 

function throttleAnimation(animation, fps) {
  var ticker = TweenLite.ticker,
      time = ticker.time,
      frameLength = 1 / fps,
      frame = 0,
      update = function() {
        var newTime = ticker.time - time,
            newFrame = ~~(newTime / frameLength);
        if (frame !== newFrame) {
          frame = newFrame;
          animation.time(newTime);
          if (animation.progress() === 1) {
            ticker.removeEventListener("tick", update);
          }
        }
      };
  animation.pause();
  ticker.addEventListener("tick", update);
}

 

Does that help? 

  • Like 3
Link to comment
Share on other sites

#whippedTogether

  • Haha 3
Link to comment
Share on other sites

AlmG7j8.jpg

  • Like 1
  • Haha 2
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.
×