Jump to content
Search Community

Set TweenLite.ticker to update when I need it?

gbish 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

I have a game running with Phaser 3 engine. It runs at a consistent 60 fps and I needed to use Gsap for it's superior animations and ease of reverse/replay, etc. The problem I have is that it's too accurate for time loss due to FPS. In other words, when the game engine drops to 30 fps. The TweenLite animation still runs and behaves as it should while the game goes half the speed.

 

Unfortunately, I can't speed up the phaser `update` calls. But I wondered if there was a way to link the next tick of the ticker to the update calls of the engine. So that when the game slows down, the tweens will as well.

 

I noticed there was a tick function in the ticker. But is there a way to manually call this in my game loop to make all the animations follow along nicely?

 

Thanks for any help.

Link to comment
Share on other sites

Sorry, I can't really think of an easy way of doing that. I suppose maybe you could set useFrames:true on all your animations and have them be frames-based, but I'm not sure that'll actually sync properly with your game engine's ticker. I wish I had an easy answer for you. It's very rare that we have people wanting to tinker with the core timing mechanism in GSAP and slow it down. :) 

Link to comment
Share on other sites

Thanks. That's why I thought I'd ask. It's really an edge case for us as this only happens if a user can change/drop the frame rate down. (Happens for me when I move from one monitor to an externally

'usb-c' ran monitor. The game drops it's frames in half.)

 

One of my ideas was to try to look for the frame rate change event and then scale the the global timeline in order to compensate the difference. But this could still make it 'out of sync' a little.

 

For anyone looking into this, this was my current solution:

setInterval(()=> {
  TweenMax.globalTimeScale(game.loop.actualFps/60) // 60 is expected, but it may change within Phaser's system.
}, 1000) // I call this every 1 second, since the game fps shouldn't change all that often.

 

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