Skip to content

Timeline

A timeline (engine.timeline()): chain to, set, call, label and wait to build it; it starts on the next frame unless made paused. Await it (or then) for its end; stop() ends it early (where it is).

  • PromiseLike<void>

new Timeline(o?): Timeline

Use engine.timeline(opts).

TimelineOptions

Timeline

repeat: number

Plays after the first (-1: forever).


yoyo: boolean

Every other play backwards.


optional onComplete?: () => void

Called when the last play ends.

void

get duration(): number

One play’s length, seconds.

number


get time(): number

Where the playhead is in the current play, seconds.

number


get paused(): boolean

Paused by pause() (or made paused).

boolean


get finished(): boolean

It ended (all its plays, or stop()).

boolean

to<T>(target, to, seconds, ease?): this

Eases target’s numeric fields to to over seconds (as engine.tween), after the previous step or at.

T extends object

T

Partial<Record<keyof T, number>>

number

Ease | StepOptions | "linear" | "quadIn" | "quadOut" | "quadInOut" | "cubicOut" | "sineInOut" | "backOut" | "elasticOut" | "bounceOut"

this

engine.timeline().to(a, { x: 600 }, 0.5).to(b, { alpha: 0 }, 0.3, { at: '<' })

set<T>(target, values, at?): this

Sets fields at once, when the playhead gets there.

T extends object

T

Partial<Record<keyof T, number>>

Position

this


call(fn, at?): this

Calls fn when the playhead passes this point (either way: a yoyo calls it going back too).

() => void

Position

this


label(name, at?): this

Names a point (default: the end so far), for at: 'name' and seek(‘name’).

string

Position

this


wait(seconds): this

A pause of seconds at the end: the next step starts after it.

number

this


pause(): this

Stops the clock where it is (game pauses stop it anyway).

this


resume(): this

Starts or goes on after pause() or { paused: true }.

this


stop(): void

Ends it now, fields where they are; the promise resolves.

void


seek(pos): this

Moves the playhead to a time or a label of the current play, writing the fields there.

Position

this


then<A, B>(ok?, fail?): Promise<A | B>

Attaches callbacks for the resolution and/or rejection of the Promise.

A = void

B = never

((v) => A | PromiseLike<A>) | null

((e) => B | PromiseLike<B>) | null

Promise<A | B>

A Promise for the completion of which ever callback is executed.

PromiseLike.then


update(dt): void

Advances by dt seconds of game time (the engine’s tweens call it).

number

void