alecmce / gaia-tween

Another tweening library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tween.reverse() / TweenForm.reverse()

alecmce opened this issue · comments

What should a reverse method look like?

Consider an ongoing tween between 0 and 100 that is at .4 (40).

(1) calling TweenForm.reverse() affects the Tween.

It would be simple to swap starts and ends, and inverse ranges for most TweenForms, but what if the tween was on-going? If the user calls reverse(), then the end would become 0, the start 100, but the user would be at 40, so the proportion should be .6.

Therefore, calling reverse() on a bound TweenForm should result in a change in the duration of the tween. A reversed():Notice would need to be constructed to notify Tween, which adds weight to the structure

(2) TweenFrom.reverse() adjusts start/end, but is not invertible

Since .4 => 40, but the new end is 0, the new start can be resolved to 66.666667. Calling reverse() again would set the new end to 66.666667, not back to 100.

Although not invertible, this would be the simplest solution since it would not affect the time. However, rather than reverse(), perhaps this implies that TweenForms should store the proportion, then if a value is set(...) during mid-tween, to change as implied above. Then, rather than reverse() ... reverse(), the user would use set("x", 0) ... set("x", 100).

One downside to this is that the tweens would become increasingly quick as the time would be immovable. However, if the user cared about that they could use tweens.add(currentTween.form ...); currentTween.cancel().

This raises an issue with the current set(...) values in PropertyTweenForm and MotionTweenForm. If they are truly 'forms', shouldn't these values be locked when the Tween is created? In which case, more separation between the TweenForm and the BoundTweenForm might be needed...

(3) Tween.reverse() could be defined

Potentially Tween.reverse could swap the update:Function reference to a vanilla_reversed or eased_reversed function to handle the swapping of values economically. This would be invertible and would keep ongoing-tween business logic properly out of the TweenForm.