Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clock synchronization issue #560

Open
christopherjbaker opened this issue Jul 29, 2020 · 4 comments
Open

Clock synchronization issue #560

christopherjbaker opened this issue Jul 29, 2020 · 4 comments

Comments

@christopherjbaker
Copy link

@christopherjbaker christopherjbaker commented Jul 29, 2020

When controlling the clock by passing a value to TWEEN.update(...), the default _startTime for a tween started with .start() still uses the browser clock, which means tweens do not behave as expected. I've fixed this in my own code by redefining TWEEN.now to return the last value I sent to .update(...). It seems to me that if its in a "controlled mode", everything should use those controlled values.

@trusktr
Copy link
Member

@trusktr trusktr commented Sep 24, 2020

That change may work for your case, but I think it may break individually-controlled Tweens. TWEEN.now() is merely supposed to be an API in place of performance.now() in case some browser doesn't have that.

If interested to make a PR but adding this feature behind an API more like TWEEN.lastTime() or similar, and update the tests, that would be great!

@trusktr
Copy link
Member

@trusktr trusktr commented Sep 24, 2020

Do you have a code snippet that demonstrates what issue you had?

@christopherjbaker
Copy link
Author

@christopherjbaker christopherjbaker commented Sep 29, 2020

I don't have a code snippet, but here is how you can recreate it:

  1. Set up a RAF that calls TWEEN.update(Date.now() + 2500). This sets up the internal clock so that it will not line up with the browser's clock. In my case, I'm using threejs's clock, which tracks in seconds instead of ms.
  2. Set up an animation that will take 5 seconds to complete. Do not pass any arguments to start().
  3. Observe that it does not behave as intended. I believe in this case, it will start halfway done, because it "started" at the current time, but the update was called with the current time + 2.5 seconds.

You've provided control of the internal clock, but you don't use the custom clock values when you start a tween, so they start in a different timeframe than the updates.

@trusktr
Copy link
Member

@trusktr trusktr commented Oct 12, 2020

Interesting, haven't used it like that before. Normally what I do is control every tween individually, which may be a workaround for now:

const tween = new Tween(...)....start(startTime)
// ...
tween.update(newTime)

That way each tween can operate with its own custom time being passed in (plus easier to encapsulate the tween to a particular component of your UI, pause it individually, update it individually, etc, while other tweens in other components can also do their own thing).

@trusktr trusktr added the Bug label Oct 12, 2020
@trusktr trusktr added this to Backlog in General Project Board via automation Oct 12, 2020
@trusktr trusktr moved this from Backlog to To do in General Project Board Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.