frameLoop
Calls onFrame once per animation frame with the time elapsed since the start, until it
returns false or the loop is cancelled: the engine behind tween, for anything that
moves on its own clock (a spring played with at(elapsedMs), a physics step, a
progress counter).
The first call happens right away, with 0, so the first state is drawn before the next
paint. Frames come from requestAnimationFrame, or a 16 ms timer where it does not exist
(Node.js, some workers).
Available since v3.1.5
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
onFrame | function | Receives the elapsed milliseconds; return `false` to stop |
options | FrameLoopOptions | Clock and cancellation — see FrameLoopOptions |
Returns
Section titled “Returns”FrameLoop — A FrameLoop, to cancel it or await its end
Examples
Section titled “Examples”Play a spring on its own clock
Section titled “Play a spring on its own clock”Return false from onFrame to stop; finished then resolves with true.
Cancel it
Section titled “Cancel it”cancel() stops it; finished resolves with false.
Related Types
Section titled “Related Types”FrameLoop
Section titled “FrameLoop”A running frameLoop.
FrameLoopOptions
Section titled “FrameLoopOptions”Options for frameLoop.
