Constructor
new Tween(callback, startopt, endopt, durationopt, optionsopt)
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.
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
callback | function | Called with the interpolated value each frame | ||||||||||||||||||||||
start | T | <optional> | 0 | Starting value | ||||||||||||||||||||
end | T | <optional> | 1 | Ending value | ||||||||||||||||||||
duration | number | <optional> | 1 | Duration in seconds | ||||||||||||||||||||
options | Object | <optional> | Properties
|
- Source
// 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) });Members
callback :function
- function
| Type | Description |
|---|---|
| function | Called with the interpolated value each frame |
- Source
duration
Properties| Type | Description |
|---|---|
| number | Total duration in seconds |
- Source
ease
Properties| Type | Description |
|---|---|
| function | Easing curve mapping [0,1] -> [0,1] |
- Source
end :T
- T
| Type | Description |
|---|---|
| T | Ending value |
- Source
end :any
- any
- Source
life
Properties| Type | Description |
|---|---|
| number | Remaining time in seconds (counts down from duration to 0) |
- Source
onComplete :undefined|function
- undefined |
function
| Type | Description |
|---|---|
| undefined | | 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 |
- Source
paused
Properties| Type | Description |
|---|---|
| boolean | If true, stop advancing until cleared |
- Source
start :T
- T
| Type | Description |
|---|---|
| T | Starting value |
- Source
start :any
- any
- Source
target
Properties| Type | Description |
|---|---|
| Object | | The object tweenProperty animates, the tween stops once it is destroyed, even while paused |
- Source
useRealTime
Properties| Type | Description |
|---|---|
| boolean | If true, advance even when the game is paused |
- Source
Methods
getPercent() → {number}
Get how far this tween has progressed, from 0 (just started) to 1 (completed). Clamped — overshoot past completion still reads 1.
- Source
- Type:
- number
getValue() → {T}
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.
- Source
- Type:
- T
interp(life) → {T}
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
| Name | Type | Description |
|---|---|---|
life | number |
- Source
- Type:
- T
isActive() → {boolean}
True if this tween is in the active list and not paused.
- Source
- Type:
- boolean
loop(countopt) → {Tween.<T>}
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.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
count | number | <optional> | Infinity |
- Source
- Type:
- Tween.<T>
pause()
Pause this tween. While paused, tweenUpdate skips it.
- Source
pingPong(countopt) → {Tween.<T>}
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.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
count | number | <optional> | Infinity |
- Source
- Type:
- Tween.<T>
restart()
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.
- Source
resume()
Resume a paused tween.
- Source
setEase(easeFn) → {Tween.<T>}
Set the easing curve and return this for chaining.
| Name | Type | Description |
|---|---|---|
easeFn | function |
- Source
- Type:
- Tween.<T>
stop()
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.
- Source
then(callback) → {Tween.<T>}
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
loopandpingPongin either order, neither replaces the other - It is kept by
restart, so a restarted tween calls it again when it completes stopandtweenStopAllend a tween without calling it
| Name | Type | Description |
|---|---|---|
callback | function |
- Source
- Type:
- Tween.<T>