Skip to content

loop()

ts
function loop(
  callback: (data: {
    time: number;
    deltaTime: number;
    elapsedTime: number;
  }) => void,
  params?: {
    immediate?: boolean;
  },
): {
  play: () => void;
  pause: () => void;
};

Creates an animation loop that calls the provided callback on every animation frame.

Parameters

callback

(data: { time: number; deltaTime: number; elapsedTime: number; }) => void

A function that will be called on every animation frame.

params?

parameters for the loop.

immediate?

boolean

If true, the loop will start immediately.

If false, the loop will start when the play method is called.

Default

ts
true;

Returns

An object with play and pause methods to control the animation loop.

NameTypeDescription
play()() => voidPlay the animation loop.
pause()() => voidPause the animation loop.

Released under the MIT License.