ITimerPlugin
Defined in: plugins/TimerPlugin.ts:417
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
Properties
app
app:
IApplication
Defined in: plugins/Plugin.ts:10
Inherited from
id
id:
string
Defined in: plugins/Plugin.ts:8
Inherited from
onAllTimersPaused
onAllTimersPaused:
Signal
<() =>void
>
Defined in: plugins/TimerPlugin.ts:449
Signal emitted when all timers are paused.
Example
this.app.timers.onAllTimersPaused.connect(() => { console.log('All timers paused');});
onAllTimersResumed
onAllTimersResumed:
Signal
<() =>void
>
Defined in: plugins/TimerPlugin.ts:460
Signal emitted when all timers are resumed.
Example
this.app.timers.onAllTimersResumed.connect(() => { console.log('All timers resumed');});
onTimerCreated
onTimerCreated:
Signal
<(timer
) =>void
>
Defined in: plugins/TimerPlugin.ts:427
Signal emitted when a new timer is created.
Example
this.app.timers.onTimerCreated.connect((timer) => { console.log(`New timer created with ID: ${timer.getId()}`);});
onTimerDestroyed
onTimerDestroyed:
Signal
<(timer
) =>void
>
Defined in: plugins/TimerPlugin.ts:438
Signal emitted when a timer is destroyed.
Example
this.app.timers.onTimerDestroyed.connect((timer) => { console.log(`Timer destroyed: ${timer.getId()}`);});
Methods
addSignalConnection()
addSignalConnection(…
args
):void
Defined in: plugins/Plugin.ts:18
Parameters
args
…SignalConnection
[]
Returns
void
Inherited from
clearSignalConnections()
clearSignalConnections():
void
Defined in: plugins/Plugin.ts:20
Returns
void
Inherited from
IPlugin
.clearSignalConnections
createTimer()
createTimer(
options
?):Timer
Defined in: plugins/TimerPlugin.ts:481
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`); }});
destroy()
destroy():
void
Defined in: plugins/Plugin.ts:16
Returns
void
Inherited from
destroyTimer()
destroyTimer(
timer
):void
Defined in: plugins/TimerPlugin.ts:495
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);
initialize()
initialize(
_app
,options
?):void
|Promise
<void
>
Defined in: plugins/Plugin.ts:12
Parameters
_app
options?
any
Returns
void
| Promise
<void
>
Inherited from
pauseAllTimers()
pauseAllTimers():
void
Defined in: plugins/TimerPlugin.ts:509
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();};
postInitialize()
postInitialize(
_app
):void
|Promise
<void
>
Defined in: plugins/Plugin.ts:14
Parameters
_app
Returns
void
| Promise
<void
>
Inherited from
registerCoreFunctions()
registerCoreFunctions():
void
Defined in: plugins/Plugin.ts:22
Returns
void
Inherited from
registerCoreSignals()
registerCoreSignals():
void
Defined in: plugins/Plugin.ts:24
Returns
void
Inherited from
resetWorkerTimer()
resetWorkerTimer(
timerId
):void
Defined in: plugins/TimerPlugin.ts:537
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());
resumeAllTimers()
resumeAllTimers():
void
Defined in: plugins/TimerPlugin.ts:523
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();};