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.
Static variables
staticglobalManager:FlxTimerManager
The global timer manager that handles global timers
4.2.0
.Constructor
Variables
read onlyelapsedTime:Float
Read-only: The amount of milliseconds that have elapsed since the timer was started
onComplete:FlxTimer ‑> Void
Function that gets called when timer completes. Callback should be formed "onTimer(Timer:FlxTimer);"
Methods
reset(NewTime:Float = -1):FlxTimer
Restart the timer using the new duration
Parameters:
NewTime | The duration of this timer in seconds. |
---|
start(Time:Float = 1, ?OnComplete:FlxTimer ‑> Void, Loops:Int = 1):FlxTimer
Starts the timer and adds the timer to the timer manager.
Parameters:
Time | How many seconds it takes for the timer to go off. If 0 then timer will fire OnComplete callback only once at the first call of update method (which means that Loops argument will be ignored). |
---|---|
OnComplete | 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).
update(elapsed:Float):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 cancel(). However, callbacks are called AFTER cancel() is called.