Skip to content

TweenGroup ​

Animate node fields and plain numbers over time.

ts
import { TweenGroup, TweenConfig } from "willow";

TweenGroup ​

ts
class TweenGroup

An 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 ​

MemberDescription
readonly done: booleanTrue once every field has reached its end value, or the target was disposed.

TweenGroup: methods ​

MemberDescription
update(dt: float): booleanAdvances 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(): voidMarks this tween for removal; the next update becomes a no-op finish.

TweenGroup: static methods ​

MemberDescription
static activeCount(): intThe number of tweens that are neither finished nor cancelled (leak checks).
static value(from: float, to: float, cfg: TweenConfig, onStep: Function): TweenGroupTweens 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): TweenGroupAnimates node.x/node.y to (toX, toY).
static alpha(node: Node, to: float, cfg: TweenConfig): TweenGroupAnimates node.alpha to to.
static color(node: Node, to: Color, cfg: TweenConfig): TweenGroupAnimates 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): TweenGroupAnimates node.rotation to to radians.
static scale(node: Node, toSX: float, toSY: float, cfg: TweenConfig): TweenGroupAnimates node.scaleX/node.scaleY to (toSX, toSY).

TweenConfig ​

ts
class TweenConfig

Duration + 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 ​

MemberDescription
duration: floatTween duration, in the same units TweenGroup.update's dt is stepped in (seconds by convention).
ease: int | FunctionEasing curve: a core Ease constant or a custom (t, b, c, d): float function. Defaults to Ease.LINEAR when omitted or null.

TweenConfig: callbacks ​

MemberDescription
onDone: FunctionOptional callback run once when the tween reaches its end. It does not run when the tween is cancelled or its target node is disposed.