Skip to content

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
// Create a 10-second countdown timer
const 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 timer
timer.pause();
// Resume the timer
timer.start();
// Reset the timer
timer.reset();

new Timer(options, plugin): Timer

Defined in: plugins/TimerPlugin.ts:249

TimerOptions = {}

TimerPlugin

Timer

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.

number

Time to add in milliseconds

number

The new time value after adjustment

// Add 5 seconds to a countdown timer
timer.addTime(5000);
// Add 5 seconds to a count-up timer
timer.addTime(5000);

destroy(): void

Defined in: plugins/TimerPlugin.ts:315

Destroys the timer, cleaning up all resources. A destroyed timer cannot be restarted.

void


getId(): string

Defined in: plugins/TimerPlugin.ts:377

Gets the unique ID of this timer.

string

The timer’s UUID


getOptions(): TimerOptions

Defined in: plugins/TimerPlugin.ts:385

Gets the timer’s configuration options.

TimerOptions

The TimerOptions object used to create this timer


getRemainingTime(): number

Defined in: plugins/TimerPlugin.ts:368

Gets the remaining time for countdown timers.

number

Remaining time in milliseconds, or 0 for count-up timers


getTime(): number

Defined in: plugins/TimerPlugin.ts:357

Gets the current time value (elapsed time for count-up, remaining time for countdown).

number

Time in milliseconds


isWorker(): boolean

Defined in: plugins/TimerPlugin.ts:393

Checks if this timer is running in a web worker.

boolean

true if the timer is worker-based, false if running on main thread


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.

void


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.

number

Time to remove in milliseconds

number

The new time value after adjustment

// Remove 5 seconds from a countdown timer
timer.removeTime(5000);
// Remove 5 seconds from a count-up timer
timer.removeTime(5000);

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.

void


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.

void


update(): void

Defined in: plugins/TimerPlugin.ts:326

void