Create a new tween. The callback fires immediately with start so the
target snaps to the start value on the same frame the tween is created.
start and end may be numbers, Vector2, Vector3 or Color instances, or
any object exposing a lerp(other, percent) => sameType method. The
callback receives the interpolated value (a number, or a fresh instance
for lerp-able types). Both endpoints must be the same type.
callback functionCalled with the interpolated value each frame
start T optional, default 0Starting value
end T optional, default 1Ending value
duration number optional, default 1Duration in seconds
options Object optionalease function optionalEasing function (defaults to LINEAR)
useRealTime boolean optional, default falseAdvance even when the game is paused (matches Timer's useRealTime)
paused boolean optional, default falseStart in paused state
// Animate a fade-out over 2 seconds with an ease-out sine curve.
new Tween((v) => obj.alpha = v, 1, 0, 2, { ease: Ease.OUT(Ease.SINE) });
Called with the interpolated value each frame
Total duration in seconds
Easing curve mapping [0,1] -> [0,1]
Remaining time in seconds (counts down from duration to 0)
Called once the tween completes: when its last pass ends,
the last iteration of a loop or pingPong, and again each time a restart plays through; then() sets it
If true, stop advancing until cleared
The object tweenProperty animates, the tween stops once it is destroyed,
even while paused
If true, advance even when the game is paused
Get how far this tween has progressed, from 0 (just started) to 1
(completed). Clamped — overshoot past completion still reads 1.
Get the current interpolated value (the value most recently passed to
the callback). Returns a number, Vector2, Vector3 or Color depending on the
tween's start/end types.
Compute the interpolated value at the given remaining life.
At life === duration the result is start; at life === 0 it is end.
- At life 0 it is the end value exactly
- A vector goes past its ends as far as the easing does, as a number does; a Color stays between them,
so its channels stay in range, and any other type goes as far as its own lerp takes it
life number
True if this tween is in the active list and not paused
Repeat this tween n total times. After each iteration finishes, the
same tween starts over, so the handle returned stays good for the whole
loop: pause or stop it to pause or stop every iteration left.
loop() with no argument loops forever.
Mutually exclusive with pingPong; calling either replaces the other.
A then callback, set before or after, is called when the last
iteration ends.
count number optional, default Infinity
Pause this tween. While paused, tweenUpdate skips it
Like loop, but swap start and end between iterations so the value
bounces back and forth. pingPong() with no argument bounces forever.
Mutually exclusive with loop; calling either replaces the other.
A then callback, set before or after, is called when the last
iteration ends.
count number optional, default Infinity
Reset this tween to the start: life back to duration, pause cleared,
re-added to the active list if previously stopped, and the callback
re-fired with the start value.
It replays one pass: a loop or pingPong that has finished is not started
over, a pingPong that ended on its way back plays that way again, and a
restart mid loop keeps the iterations left. Call loop or pingPong again
after restart to repeat it. The then callback is kept and is called
again when it completes.
Set the easing curve and return this for chaining
easeFn function
Remove this tween from the active list, ending a loop or pingPong too, without calling
the then-callback. It keeps the then-callback, so a restart calls it when it completes.
Set the completion callback, onComplete, and return this for chaining.
It is called once the tween completes: when its pass ends, or for a
loop or pingPong when its last iteration ends, so an endless one
never calls it. Calling then again replaces the previous callback.
- It works with
loop and pingPong in either order, neither replaces the other
- It is kept by
restart, so a restarted tween calls it again when it completes
stop and tweenStopAll end a tween without calling it
callback function