Timer
Defined in: plugins/TimerPlugin.ts:227
A Timer instance that can count down or up, optionally running in a web worker.
Features:
- Count down from a duration or count up indefinitely
- Run in main thread (synced with Pixi ticker) or web worker
- Pause, resume, and reset functionality
- Loop option for repeating timers
- Tick and completion callbacks
Example
// Create a 10-second countdown timerconst timer = new Timer({ duration: 10000, autoStart: true, loop: true, onTick: (remaining) => { console.log(`${remaining / 1000} seconds remaining`); }, onComplete: () => { console.log('Timer completed!'); }}, timerPlugin);
// Pause the timertimer.pause();
// Resume the timertimer.start();
// Reset the timertimer.reset();
Constructors
new Timer()
new Timer(
options
,plugin
):Timer
Defined in: plugins/TimerPlugin.ts:235
Parameters
options
TimerOptions
= {}
plugin
Returns
Methods
destroy()
destroy():
void
Defined in: plugins/TimerPlugin.ts:301
Destroys the timer, cleaning up all resources. A destroyed timer cannot be restarted.
Returns
void
getId()
getId():
string
Defined in: plugins/TimerPlugin.ts:357
Gets the unique ID of this timer.
Returns
string
The timer’s UUID
getOptions()
getOptions():
TimerOptions
Defined in: plugins/TimerPlugin.ts:365
Gets the timer’s configuration options.
Returns
The TimerOptions object used to create this timer
getRemainingTime()
getRemainingTime():
number
Defined in: plugins/TimerPlugin.ts:348
Gets the remaining time for countdown timers.
Returns
number
Remaining time in milliseconds, or 0 for count-up timers
getTime()
getTime():
number
Defined in: plugins/TimerPlugin.ts:337
Gets the current time value (elapsed time for count-up, remaining time for countdown).
Returns
number
Time in milliseconds
isWorker()
isWorker():
boolean
Defined in: plugins/TimerPlugin.ts:373
Checks if this timer is running in a web worker.
Returns
boolean
true if the timer is worker-based, false if running on main thread
pause()
pause():
void
Defined in: plugins/TimerPlugin.ts:270
Pauses the timer, maintaining its current state. The timer can be resumed later from the same point.
Returns
void
reset()
reset():
void
Defined in: plugins/TimerPlugin.ts:285
Resets the timer to its initial state. If the timer is not paused, it will start running immediately after reset.
Returns
void
start()
start():
void
Defined in: plugins/TimerPlugin.ts:255
Starts or resumes the timer. If the timer was paused, it will continue from where it left off.
Returns
void
update()
update():
void
Defined in: plugins/TimerPlugin.ts:306
Returns
void