Skip to content

Commit

Permalink
add FlxTimer.wait
Browse files Browse the repository at this point in the history
  • Loading branch information
Geokureli committed Feb 19, 2024
1 parent 27324ef commit 5b3aa8c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions flixel/util/FlxTimer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ import flixel.util.FlxDestroyUtil.IFlxDestroyable;
*/
class FlxTimer implements IFlxDestroyable
{
/**
* Handy tool to create and start a `FlxTimer`
* @param time The duration of the timer, in seconds. If `0` then `onComplete`
* fires on the next game update, and the `loops` argument is ignored.
* @param onComplete Optional, triggered whenever the time runs out, once for each loop.
* Callback should be formed `onTimer(Timer:FlxTimer);`
* @param loops How many times the timer should go off. `0` means "looping forever".
* @return The `FlxTimer` instance
*/
public static inline function wait(time:Float, callback:(FlxTimer)->Void, loops = 1)
{
return new FlxTimer().start(time, onComplete, loops);
}

/**
* The global timer manager that handles global timers
* @since 4.2.0
Expand Down Expand Up @@ -115,14 +129,14 @@ class FlxTimer implements IFlxDestroyable
/**
* Starts the timer and adds the timer to the timer manager.
*
* @param 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).
* @param time The duration of the timer, in seconds. If `0` then `onComplete`
* fires on the next game update, and the `loops` argument is ignored.
* @param onComplete Optional, triggered whenever the time runs out, once for each loop.
* Callback should be formed "onTimer(Timer:FlxTimer);"
* Callback should be formed `onTimer(Timer:FlxTimer);`
* @param loops How many times the timer should go off. 0 means "looping forever".
* @return A reference to itself (handy for chaining or whatever).
*/
public function start(time:Float = 1, ?onComplete:FlxTimer->Void, loops:Int = 1):FlxTimer
public function start(time:Float = 1, ?onComplete:(FlxTimer)->Void, loops:Int = 1):FlxTimer
{
if (manager != null && !_inManager)
{
Expand Down

0 comments on commit 5b3aa8c

Please sign in to comment.