class flixel.util.FlxTimer implements IFlxDestroyable

Available on all platforms

A simple timer class, leveraging the new plugins system. * Can be used with callbacks or by polling the finished flag. * Not intended to be added to a game state or group; the timer manager * is responsible for actually calling update(), not the user.

Class Fields

static var manager:TimerManager

The TimerManager instance.

Instance Fields

var active:Bool

Pauses or checks the pause state of the timer.

var elapsedLoops:Int

Read-only: how many loops that have elapsed since the timer was started.

var elapsedTime:Float

Read-only: The amount of milliseconds that have elapsed since the timer was started

var finished:Bool

Check to see if the timer is finished.

var loops:Int

How many loops the timer was set for. 0 means "looping forever".

var loopsLeft:Int

Read-only: check how many loops are left on the timer.

var progress:Float

Read-only: how far along the timer is, on a scale of 0.0 to 1.0.

var time:Float

How much time the timer was set for.

var timeLeft:Float

Read-only: check how much time is left on the timer.

function new(?Time:Float = null, ?Callback:FlxTimer ->Void = null, ?Loops:Int = 1):Void

Creates a new timer (and calls start() right away if Time != null). * *

Time

How many seconds it takes for the timer to go off. *

Callback

Optional, triggered whenever the time runs out, once for each loop. Callback should be formed "onTimer(Timer:FlxTimer);" *

Loops

How many times the timer should go off. 0 means "looping forever".

function cancel():Void

Stops the timer and removes it from the timer manager.

function complete(:FlxTimer):Void

Function that gets called when timer completes. * Callback should be formed "onTimer(Timer:FlxTimer);"

function destroy():Void

Clean up memory.

function reset(?NewTime:Float = -1):FlxTimer

Restart the timer using the new duration *

NewDuration

The duration of this timer in ms.

function start(?Time:Float = 1, ?Callback:FlxTimer ->Void = null, ?Loops:Int = 1):FlxTimer

Starts the timer and adds the timer to the timer manager. * *

Time

How many seconds it takes for the timer to go off. *

Callback

Optional, triggered whenever the time runs out, once for each loop. Callback should be formed "onTimer(Timer:FlxTimer);" *

Loops

How many times the timer should go off. 0 means "looping forever". *

returns

A reference to itself (handy for chaining or whatever).

function update():Void

Called by the timer manager plugin to update the timer. * If time runs out, the loop counter is advanced, the timer reset, and the callback called if it exists. * If the timer runs out of loops, then the timer calls stop(). * However, callbacks are called AFTER stop() is called.