playcanvas / playcanvas-tween

A tween library for PlayCanvas
MIT License
59 stars 46 forks source link

Can re-use same tweens #32

Closed nikitaosyak closed 2 years ago

nikitaosyak commented 2 years ago

Hello.

I would like to propose this simple change to have the ability of pooling tweens.

In my project I wanted to evade constantly creating tween objects, so I stick with re-using all the repeating tweens. It turned out, that there was a bug in TweenManager, that allowed adding the same tween more then one time to the current _tweens array, which caused tween speedup by a factor of how many times same tween instance was added.

I've thrown together demo project so you can see the problem https://playcanvas.com/project/926296/overview/pooltweenexample

Here's how it looks

https://user-images.githubusercontent.com/1550079/167999454-f102d20f-af2b-4256-bd39-affc0ca847e5.mp4

I confirm I have signed the Contributor License Agreement.