-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
onRepeat not getting getting called when time is close to a multiple of the duration of a tween #593
Comments
Yes, there is rounding that occurs internally in order to protect against a bunch of edge cases (trust me, it's a good thing). So I'd recommend applying similar logic in your code. For example: |
Hello, thank you for the quick response and suggestion! Unfortunately I don't think this method will work in general. We have some durations which are calculated from other parameters and they are not always integers. See here for example: https://codepen.io/mdat/pen/OJeqWrd?editors=0012 If we set the scale to 1 it works, but if scale up the duration and times by a factor of 1.1, which should in theory keep the same behavior the bug still reproduces. Do you have any suggestions for a general workaround? |
Sure, you're just doing the correction at the wrong spot. Here's an even easier solution: |
When the time lands on values that are close (but not exactly equal) to a multiple of the duration of a tween, the onRepeat call will not be called.
Here is an example:
In this case we see only 2 console.log's (when the time reaches 3 and 12.5 - which are either equal or after the repeat time), but we expect 4 console.log's (also when the time is close to 6 and 9).
Here is a full reproduction example: https://codepen.io/mdat/pen/wvLOMwV
And here is an example with other slightly changed time values which works as expected (called 4 times): https://codepen.io/mdat/pen/qBzvNGp
This might not seem important for a real-world application, but if the framerate is consistent and we happen to choose a duration which is multiple of it, it is quite possible to sometimes land on a value this close to it and get unexpected behavior. Which happened to our team and it was quite difficult to debug.
The text was updated successfully, but these errors were encountered: