tween.js
tween.js copied to clipboard
Multiple `.start()` and `.to(prop:[])`
Related Issues
- Animation on repeat speeds up over time. #378
Purpose of this Pull Request
This PR fixes the Issue of tween acceleration on multiple .start().
If an object with an array is passed to .to()
, _valuesEnd
will be irreversibly changed when .start()
is executed multiple times.
As a result, each time you run .start()
, animation will be faster.
Details of the changes
- Added test cases.
- Added
_hasSetupProperty
flag to check if_setupProperties()
has been executed. - If you reconfigure
.to()
, startValue will be changed to the current value of the tween target object. Check_valuesStart
and keep it if it is already initialized.
https://github.com/tweenjs/tween.js/blob/ae24c58c8b57b2079151ae2c3c63f2bb501c8b2b/src/Tween.ts#L169-L172
I used this code as a reference for change point 3.
Related pull requests
- Fix dynamic to with array values #585
I think it might be difficult to merge this PR as-is, because of conflicts with features such as dynamic to
and _propertiesAreSetUp
. In that case, I hope the added test cases will contribute to everyone.
@MasatoMakino Thanks for this! Would you mind making an example for this?
The more I see changes and fixes like these, the more I start to want to start working on a Timeline/Keyframe/Tween abstraction. It seems Tween is trying to do too much, all in one.
@MasatoMakino Thanks for this! Would you mind making an example for this?
@trusktr Thanks for your reply.
I have made examples of multiple start with CodePen. tween.js 18.6.4 : multiple start and array tween.js 18.6.4 + PR #602 : multiple start and array
I also considered adding a new page in ./examples
.
However, it is hard to tell what is a difference between examples of multiple start and example of repeat, and there is a risk of confusing users. I did not add examples of multiple start to this PR, but made examples with codepen.
Closes #378
Looks like this got fixed already!
https://codepen.io/trusktr/pen/XWGpKyX/10faa7d954bf016a3f0261ca626db17e?editors=1010
There's a similar issue with startWithCurrentValues()
, but the problem is gone when using start()
. See this issue:
- https://github.com/tweenjs/tween.js/issues/378