TimerPlugin
Defined in: plugins/TimerPlugin.ts:540
Interface for the Timer Plugin which manages both main-thread and web worker timers.
The Timer Plugin provides functionality for:
- Creating and managing countdown and count-up timers
- Running timers in a web worker for better performance
- Pausing and resuming all timers
- Handling timer lifecycle events
Example
// Create a 5-second countdown timerconst countdown = this.app.timers.createTimer({ duration: 5000, autoStart: true, onTick: (remaining) => { console.log(`Time remaining: ${formatTime(remaining, 'mm:ss')}`); }, onComplete: () => { console.log('Timer completed!'); }});
// Create a count-up timer in a web workerconst stopwatch = this.app.timers.createTimer({ useWorker: true, workerInterval: 100, // Update every 100ms onTick: (elapsed) => { console.log(`Time elapsed: ${formatTime(elapsed, 'mm:ss')}`); }});
// Pause all timersthis.app.timers.pauseAllTimers();
// Resume all timersthis.app.timers.resumeAllTimers();
Extends
Implements
Constructors
new TimerPlugin()
new TimerPlugin():
TimerPlugin
Defined in: plugins/TimerPlugin.ts:557
Returns
Overrides
Properties
__dill_pixel_method_binding_root
__dill_pixel_method_binding_root:
boolean
Defined in: plugins/Plugin.ts:37
Inherited from
Plugin
.__dill_pixel_method_binding_root
id
id:
string
='Plugin'
Defined in: plugins/Plugin.ts:40
Implementation of
Inherited from
onAllTimersPaused
readonly
onAllTimersPaused:Signal
<() =>void
>
Defined in: plugins/TimerPlugin.ts:554
Signal emitted when all timers are paused.
Example
this.app.timers.onAllTimersPaused.connect(() => { console.log('All timers paused');});
Implementation of
ITimerPlugin
.onAllTimersPaused
onAllTimersResumed
readonly
onAllTimersResumed:Signal
<() =>void
>
Defined in: plugins/TimerPlugin.ts:555
Signal emitted when all timers are resumed.
Example
this.app.timers.onAllTimersResumed.connect(() => { console.log('All timers resumed');});
Implementation of
ITimerPlugin
.onAllTimersResumed
onTimerCreated
readonly
onTimerCreated:Signal
<(timer
) =>void
>
Defined in: plugins/TimerPlugin.ts:552
Signal emitted when a new timer is created.
Example
this.app.timers.onTimerCreated.connect((timer) => { console.log(`New timer created with ID: ${timer.getId()}`);});
Implementation of
onTimerDestroyed
readonly
onTimerDestroyed:Signal
<(timer
) =>void
>
Defined in: plugins/TimerPlugin.ts:553
Signal emitted when a timer is destroyed.
Example
this.app.timers.onTimerDestroyed.connect((timer) => { console.log(`Timer destroyed: ${timer.getId()}`);});
Implementation of
Accessors
app
Get Signature
get app():
T
Defined in: plugins/Plugin.ts:45
Returns
T
Implementation of
Inherited from
hasWorkerSupport
Get Signature
get hasWorkerSupport():
boolean
Defined in: plugins/TimerPlugin.ts:548
Returns
boolean
Methods
addSignalConnection()
addSignalConnection(…
args
):void
Defined in: plugins/Plugin.ts:71
Add signal connections to the container.
Parameters
args
…SignalConnection
[]
The signal connections to add.
Returns
void
Implementation of
ITimerPlugin
.addSignalConnection
Inherited from
clearSignalConnections()
clearSignalConnections():
void
Defined in: plugins/Plugin.ts:77
Returns
void
Implementation of
ITimerPlugin
.clearSignalConnections
Inherited from
createTimer()
createTimer(
options
?):Timer
Defined in: plugins/TimerPlugin.ts:675
Creates a new timer with the specified options.
Parameters
options?
Configuration options for the timer
Returns
A new Timer instance
Example
// Create a looping timer that runs in a web workerconst timer = this.app.timers.createTimer({ duration: 1000, loop: true, useWorker: true, onTick: (remaining) => { console.log(`${remaining}ms remaining`); }});
Implementation of
destroy()
destroy():
void
Defined in: plugins/TimerPlugin.ts:658
Returns
void
Implementation of
Overrides
destroyTimer()
destroyTimer(
timer
):void
Defined in: plugins/TimerPlugin.ts:689
Destroys a timer, cleaning up all resources and removing it from the plugin.
Parameters
timer
The timer instance to destroy
Returns
void
Example
const timer = this.app.timers.createTimer({ duration: 5000 });// ... later ...this.app.timers.destroyTimer(timer);
Implementation of
initialize()
initialize(
app
):Promise
<void
>
Defined in: plugins/TimerPlugin.ts:569
Parameters
app
Returns
Promise
<void
>
Implementation of
Overrides
pauseAllTimers()
pauseAllTimers():
void
Defined in: plugins/TimerPlugin.ts:703
Pauses all active timers, both main thread and worker timers. Timers will maintain their current state and can be resumed later.
Returns
void
Example
// Pause all timers when the game loses focuswindow.onblur = () => { this.app.timers.pauseAllTimers();};
Implementation of
postInitialize()
postInitialize(
_app
):void
|Promise
<void
>
Defined in: plugins/Plugin.ts:60
Parameters
_app
Returns
void
| Promise
<void
>
Implementation of
Inherited from
resetWorkerTimer()
resetWorkerTimer(
timerId
):void
Defined in: plugins/TimerPlugin.ts:639
Resets a worker timer to its initial state. This is primarily used internally by the Timer class.
Parameters
timerId
string
The ID of the worker timer to reset
Returns
void
Example
// This is typically called internally by the Timer classthis.app.timers.resetWorkerTimer(timer.getId());
Implementation of
resumeAllTimers()
resumeAllTimers():
void
Defined in: plugins/TimerPlugin.ts:711
Resumes all paused timers, both main thread and worker timers. Timers will continue from their paused state.
Returns
void
Example
// Resume all timers when the game regains focuswindow.onfocus = () => { this.app.timers.resumeAllTimers();};
Implementation of
startWorkerTimer()
startWorkerTimer(
timerId
,options
):void
Defined in: plugins/TimerPlugin.ts:614
Parameters
timerId
string
options
Returns
void
stopWorkerTimer()
stopWorkerTimer(
timerId
):void
Defined in: plugins/TimerPlugin.ts:629
Parameters
timerId
string
Returns
void