TweenGroup
Animate node fields and plain numbers over time.
ts
import { TweenGroup, TweenConfig } from "willow";TweenGroup
ts
class TweenGroupAn in-flight interpolation over up to 4 fields of a single Node, returned by the TweenGroup.* static factories below. A disposed target node ends the tween silently rather than raising. TweenGroup.value tweens a plain number with no node.
TweenGroup: properties
| Member | Description |
|---|---|
readonly done: boolean | True once every field has reached its end value, or the target was disposed. |
TweenGroup: methods
| Member | Description |
|---|---|
update(dt: float): boolean | Advances this tween by dt (same units as TweenConfig.duration) ON TOP of the automatic per-frame step, so a script that calls it every frame runs its tween at double speed. It exists for deterministic stepping in tests. Returns true once finished. A no-op returning true once already done or cancelled. |
cancel(): void | Marks this tween for removal; the next update becomes a no-op finish. |
TweenGroup: static methods
| Member | Description |
|---|---|
static activeCount(): int | The number of tweens that are neither finished nor cancelled (leak checks). |
static value(from: float, to: float, cfg: TweenConfig, onStep: Function): TweenGroup | Tweens a plain number from from to to with no node. onStep(v) runs on every step, and once with exactly to at the end, then cfg.onDone runs. Cancelling stops both. |
static position(node: Node, toX: float, toY: float, cfg: TweenConfig): TweenGroup | Animates node.x/node.y to (toX, toY). |
static alpha(node: Node, to: float, cfg: TweenConfig): TweenGroup | Animates node.alpha to to. |
static color(node: Node, to: Color, cfg: TweenConfig): TweenGroup | Animates a node's colour field (tint on Sprite; color on Quad/Text/Polygon) to to. Raises a TypeError if the node has neither field. |
static rotation(node: Node, to: float, cfg: TweenConfig): TweenGroup | Animates node.rotation to to radians. |
static scale(node: Node, toSX: float, toSY: float, cfg: TweenConfig): TweenGroup | Animates node.scaleX/node.scaleY to (toSX, toSY). |
TweenConfig
ts
class TweenConfigDuration + easing curve for a tween. ease is a core Ease constant or, for a custom curve, a function (t, b, c, d): float (t elapsed, b begin, c change, d duration). It defaults to Ease.LINEAR when omitted or null. duration is in the same units TweenGroup.update's dt is stepped in (seconds by convention, matching Node.onUpdate's dt).
TweenConfig: constructors
ts
new TweenConfig(duration: float, ease?: int | Function, onDone?: Function)TweenConfig: properties
| Member | Description |
|---|---|
duration: float | Tween duration, in the same units TweenGroup.update's dt is stepped in (seconds by convention). |
ease: int | Function | Easing curve: a core Ease constant or a custom (t, b, c, d): float function. Defaults to Ease.LINEAR when omitted or null. |
TweenConfig: callbacks
| Member | Description |
|---|---|
onDone: Function | Optional callback run once when the tween reaches its end. It does not run when the tween is cancelled or its target node is disposed. |