Playback

View source

Represents mutable timing state used to advance one animation.

It advances an animation position while active and applies the selected PlaybackRepeat rule at the duration boundary. It does not load or validate animation data, so callers provide the timing context and decide how to use the resulting position.

Examples

import { AnimationPlayer, Playback, PlaybackRepeat } from '@wimaengine/animation'

const player = new AnimationPlayer()
const playback = new Playback({
  duration: 2,
  repeatMode: PlaybackRepeat.Forever
})

player.animations.set(42, playback)
playback.update(0.5)
console.log(playback.elapsed) // 0.5

Constructor


constructor(options?: PlaybackSettings)

View source

Creates playback state with a duration of 1, normal speed, no repeat, zero elapsed time, and an unpaused state unless the value is changed after construction.

elapsed and paused are initialized by the class fields and are not constructor options. The constructor does not validate the supplied numbers or repeat mode.

Parameters

NameDescriptionDefault
options?

Initial duration, speed, and repeat mode.

{}

Properties


speed: number

View source

Multiplier applied to the delta passed to Playback#update. A value of 1 advances at normal speed, while 0 leaves elapsed time unchanged during an update. No range or finiteness check is performed.

paused: boolean

View source

Whether updates are ignored. A new playback is unpaused; pausing preserves the current elapsed value.

Default: false

Methods


staticdefault(): Playback

View source

Creates playback with its constructor defaults.

Returns

A new default playback value.

staticcopy(source: Playback, target?: Playback): Playback

View source

Copies all playback fields into a playback value.

The five scalar fields are assigned directly. If target is omitted, a new Playback is created; if it is supplied, that same object is populated and returned.

Parameters

NameDescriptionDefault
source

Playback state to copy.

—
target?

Value to populate.

...

Returns

The populated target playback.

staticclone(target: Playback): Playback

View source

Creates an independent playback value with the same scalar state.

Parameters

NameDescriptionDefault
target

Playback state to clone.

—

Returns

A new playback value.

staticserialize(value: Playback): PlaybackSerial

View source

Converts playback state to its serializable five-field representation.

The returned object contains speed, duration, elapsed, repeatMode, and paused in that shape; it is a new object and does not modify the playback value.

Parameters

NameDescriptionDefault
value

Playback state to serialize.

—

Returns

Serialized playback state.

staticdeserialize(value: PlaybackSerial, out?: Playback): Playback

View source

Restores serialized fields into a playback value.

The supplied out value is updated in place, or a new Playback is created when it is omitted. This method copies fields without validating them; call Playback.validateSerial first for untrusted input.

Parameters

NameDescriptionDefault
value

Serialized playback state.

—
out?

Value to populate.

...

Returns

The populated output playback.

staticvalidateSerial(value: unknown): value is PlaybackSerial

View source

Checks the shallow serialized shape used by Playback.deserialize.

A non-null object must contain all five fields with number types for speed, duration, elapsed, and repeatMode, and a boolean type for paused. The validator does not check finite values, numeric ranges, or whether repeatMode is one of PlaybackRepeat’s values. The current implementation does not guard null, so callers must pass a non-null value or guard it before calling.

Parameters

NameDescriptionDefault
value——

Returns

Whether the value has the required field types.

start(): void

View source

Resets elapsed time to 0 and resumes playback.

stop(): void

View source

Resets elapsed time to 0 and pauses playback.

play(): void

View source

Resumes playback without changing elapsed time.

pause(): void

View source

Pauses playback at its current elapsed time.

update(delta: number): void

View source

Advances elapsed time unless the playback is paused.

The effective step is delta * speed. With PlaybackRepeat.None, elapsed time is capped at duration with Math.min, so a negative step is not clamped at zero. With PlaybackRepeat.Forever, elapsed time is reduced modulo duration and therefore wraps after each duration. Any other numeric repeat value leaves the effective step unnormalized. A zero duration in repeat mode follows JavaScript remainder behavior and produces NaN.

Parameters

NameDescriptionDefault
delta

Time step in the same units as duration.

—