Static methods

staticset(callback:() ‑> Void, delay:Float):Timer

Creates and immediately starts a timer.

This is the shortest way to schedule a one-shot callback.

Parameters:

callback

Function to call when the timer fires.

delay

Delay in seconds.

Returns:

The created timer.

Constructor

new(callback:() ‑> Void, delay:Float)

Creates a timer without starting it.

Use start, repeat, or loop to activate it later.

Parameters:

callback

Function to call when the timer fires.

delay

Delay in seconds.

Variables

started:Bool

Whether the timer is currently scheduled.

Setting this to true starts the timer, and setting it to false stops it.

Methods

@:value({ lock : true })loop(lock:Bool = true):Bool

Starts the timer as an infinite loop.

This is a convenience alias for repeat(0, lock).

Parameters:

lock

Whether to skip starting when the timer is already running.

Returns:

true if looping was started.

@:value({ lock : true, count : 1 })repeat(count:Int = 1, lock:Bool = true):Bool

Starts the timer repeatedly.

Repetitions are driven by scaled time, just like start.

Parameters:

count

Number of repetitions. Use 0 for an infinite repeat.

lock

Whether to skip starting when the timer is already running.

Returns:

true if repeating was started.

@:value({ lock : true })start(lock:Bool = true):Bool

Starts the timer.

Starting resets the active callback chain back to the original one-shot callback.

Parameters:

lock

Whether to skip starting when the timer is already running.

Returns:

true if the timer was started.

stop():Void

Stops the timer if it is scheduled.

This also restores the original callback when the timer had been configured through repeat or loop.