- Version
- 1.1.0
- License
- MIT
- Source
- RafLoop.js, line 11
Constructor
new RafLoop(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.
- Type
- function
- Source
- RafLoop.js, line 16
private #timerId :number|null
Current timer ID (RAF or interval), or null if stopped.
- Type
- number | null
- Source
- RafLoop.js, line 22
private #interval :number|null
The update interval in milliseconds. If null, uses requestAnimationFrame.
- Type
- number | null
- Source
- RafLoop.js, line 28
private #tickLimit :number|null
The maximum number of frames/ticks to run, or null for unlimited.
- Type
- number | null
- Source
- RafLoop.js, line 34
private #tickCount :number
Current tick/frame count for a limited run.
- Type
- number
- Source
- RafLoop.js, line 40
private #frameCount :number
Number of frames/ticks since the last FPS calculation.
- Type
- number
- Source
- RafLoop.js, line 46
private #lastFpsUpdate :number
Timestamp of the last FPS calculation.
- Type
- number
- Source
- RafLoop.js, line 52
private #currentFps :number
Most recent calculated FPS value.
- Type
- number
- Source
- RafLoop.js, line 58
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. |
- Source
- RafLoop.js, line 78
stop()
Stops the loop if running.
- Source
- RafLoop.js, line 108
isRunning() → boolean
Returns whether the loop is currently running.
- Returns
-
True if the loop is active, false otherwise.
- Type boolean
- Source
- RafLoop.js, line 127
getFPS() → number
Returns the currently measured frames/ticks per second (FPS/TPS).
- Returns
-
The most recent FPS/TPS value, updated once per second.
- Type number
- Source
- RafLoop.js, line 135
private #tickRAF()
Internal tick method for RAF mode.
- Source
- RafLoop.js, line 143
private #tickInterval()
Internal tick method for interval mode.
- Source
- RafLoop.js, line 152
private #handleTick()
Internal tick logic shared by RAF and interval. Increments tick counter, handles limit and FPS calculation.
- Source
- RafLoop.js, line 161
destroy()
Performs full cleanup by stopping the loop and clearing the render function. Should be called when the instance is no longer needed.
- Source
- RafLoop.js, line 187