Timer
Defined in: plugins/TimerPlugin.ts:241
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
Section titled “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
Section titled “Constructors”Constructor
Section titled “Constructor”new Timer(
options
,plugin
):Timer
Defined in: plugins/TimerPlugin.ts:249
Parameters
Section titled “Parameters”options
Section titled “options”TimerOptions
= {}
plugin
Section titled “plugin”Returns
Section titled “Returns”Timer
Methods
Section titled “Methods”addTime()
Section titled “addTime()”addTime(
ms
):number
Defined in: plugins/TimerPlugin.ts:413
Adds time to the timer. For countdown timers, this increases the duration. For count-up timers, this effectively adds time to the elapsed time.
Parameters
Section titled “Parameters”number
Time to add in milliseconds
Returns
Section titled “Returns”number
The new time value after adjustment
Example
Section titled “Example”// Add 5 seconds to a countdown timertimer.addTime(5000);
// Add 5 seconds to a count-up timertimer.addTime(5000);
destroy()
Section titled “destroy()”destroy():
void
Defined in: plugins/TimerPlugin.ts:315
Destroys the timer, cleaning up all resources. A destroyed timer cannot be restarted.
Returns
Section titled “Returns”void
getId()
Section titled “getId()”getId():
string
Defined in: plugins/TimerPlugin.ts:377
Gets the unique ID of this timer.
Returns
Section titled “Returns”string
The timer’s UUID
getOptions()
Section titled “getOptions()”getOptions():
TimerOptions
Defined in: plugins/TimerPlugin.ts:385
Gets the timer’s configuration options.
Returns
Section titled “Returns”The TimerOptions object used to create this timer
getRemainingTime()
Section titled “getRemainingTime()”getRemainingTime():
number
Defined in: plugins/TimerPlugin.ts:368
Gets the remaining time for countdown timers.
Returns
Section titled “Returns”number
Remaining time in milliseconds, or 0 for count-up timers
getTime()
Section titled “getTime()”getTime():
number
Defined in: plugins/TimerPlugin.ts:357
Gets the current time value (elapsed time for count-up, remaining time for countdown).
Returns
Section titled “Returns”number
Time in milliseconds
isWorker()
Section titled “isWorker()”isWorker():
boolean
Defined in: plugins/TimerPlugin.ts:393
Checks if this timer is running in a web worker.
Returns
Section titled “Returns”boolean
true if the timer is worker-based, false if running on main thread
pause()
Section titled “pause()”pause():
void
Defined in: plugins/TimerPlugin.ts:284
Pauses the timer, maintaining its current state. The timer can be resumed later from the same point.
Returns
Section titled “Returns”void
removeTime()
Section titled “removeTime()”removeTime(
ms
):number
Defined in: plugins/TimerPlugin.ts:448
Removes time from the timer. For countdown timers, this decreases the duration. For count-up timers, this effectively removes time from the elapsed time.
Parameters
Section titled “Parameters”number
Time to remove in milliseconds
Returns
Section titled “Returns”number
The new time value after adjustment
Example
Section titled “Example”// Remove 5 seconds from a countdown timertimer.removeTime(5000);
// Remove 5 seconds from a count-up timertimer.removeTime(5000);
reset()
Section titled “reset()”reset():
void
Defined in: plugins/TimerPlugin.ts:299
Resets the timer to its initial state. If the timer is not paused, it will start running immediately after reset.
Returns
Section titled “Returns”void
start()
Section titled “start()”start():
void
Defined in: plugins/TimerPlugin.ts:269
Starts or resumes the timer. If the timer was paused, it will continue from where it left off.
Returns
Section titled “Returns”void
update()
Section titled “update()”update():
void
Defined in: plugins/TimerPlugin.ts:326
Returns
Section titled “Returns”void