Constructor
new Looper(renderFn, intervalopt)
Creates a new RAFLoop instance.
| Name | Type | Attributes | Description |
|---|---|---|---|
renderFn |
function |
The function to execute on each frame/tick. Must not be null. |
|
interval |
number | optional |
Optional: update interval in milliseconds. If omitted or falsy, uses requestAnimationFrame. |
- Throws
-
If renderFn is not a function.
Type TypeError
Members
private #renderFn :function
The user-defined render function to be called on each frame/tick.
private #timerId :number|null
Current timer ID (RAF or interval), or null if stopped.
private #interval :number|null
The update interval in milliseconds. If null, uses requestAnimationFrame.
private #tickLimit :number|null
The maximum number of frames/ticks to run, or null for unlimited.
private #tickCount :number
private #frameCount :number
private #lastFpsUpdate :number
private #currentFps :number
Methods
start(limitopt)
Starts the loop if not already running. Optionally limits the number of ticks/frames. If called again while running, changes the tick limit or makes the loop unlimited.
| Name | Type | Attributes | Description |
|---|---|---|---|
limit |
number | optional |
Optional maximum number of ticks; unlimited if omitted or invalid. |
stop()
isRunning() → boolean
Returns whether the loop is currently running.
getFPS() → number
Returns the currently measured frames/ticks per second (FPS/TPS).
private #tickRAF()
private #handleTick()
Internal tick logic shared by RAF and interval. Increments tick counter, handles limit and FPS calculation.