From 9ba9d288cf5fe0a3659d3ea6d1dd7e640b3a4213 Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Wed, 18 Mar 2026 09:43:51 -0700 Subject: [PATCH 1/9] Add function to complete the callback early. Needed for a personal use-case, was told to give contributing to the main source code a go. --- flixel/util/FlxTimer.hx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 4495fc7d3a..1e01f3d12a 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -220,6 +220,19 @@ class FlxTimer implements IFlxDestroyable } } + /*** + * Ends a loop early and runs onComplete(), regardless of how much time is left. + */ + public function completeEarly():Void + { + if (active && !finished){ + _timeCounter -= time; + _loopsCounter++; + + onLoopFinished(); + } + } + @:allow(flixel.util.FlxTimerManager) function onLoopFinished():Void { From a8876f61b8ae95679734512f5aea49796b9d268c Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Wed, 18 Mar 2026 13:43:55 -0700 Subject: [PATCH 2/9] Update description to match formatting. Co-authored-by: George Kurelic --- flixel/util/FlxTimer.hx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 1e01f3d12a..868175b35a 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -220,9 +220,9 @@ class FlxTimer implements IFlxDestroyable } } - /*** - * Ends a loop early and runs onComplete(), regardless of how much time is left. - */ + /** + * Ends a loop early and calls onComplete(), regardless of how much time is left. + */ public function completeEarly():Void { if (active && !finished){ From 887c0b106a5afbc7d936aa6025e92e2117369d7b Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:08:19 -0700 Subject: [PATCH 3/9] Update function name as per suggestion. Easier and shorter! --- flixel/util/FlxTimer.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 868175b35a..95cf4aa44f 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -223,7 +223,7 @@ class FlxTimer implements IFlxDestroyable /** * Ends a loop early and calls onComplete(), regardless of how much time is left. */ - public function completeEarly():Void + public function complete():Void { if (active && !finished){ _timeCounter -= time; From bea0627835c98c4996a36c97bb246e032402900f Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:32:04 -0700 Subject: [PATCH 4/9] Fix _timeCounter behaviour going below zero when complete --- flixel/util/FlxTimer.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 95cf4aa44f..78b99c047b 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -226,7 +226,7 @@ class FlxTimer implements IFlxDestroyable public function complete():Void { if (active && !finished){ - _timeCounter -= time; + _timeCounter = 0; _loopsCounter++; onLoopFinished(); From a01485587756e63c5b86dfc9f95897f0ccd3047a Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Thu, 19 Mar 2026 02:37:09 -0700 Subject: [PATCH 5/9] Fixed complete() restarting a timer's loop, even if was the last one. Basically just a little sanity check in there to call the complete function. There might be a better way to do this, but it appears to work just fine. --- flixel/util/FlxTimer.hx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 78b99c047b..1811b8e6e7 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -223,15 +223,20 @@ class FlxTimer implements IFlxDestroyable /** * Ends a loop early and calls onComplete(), regardless of how much time is left. */ - public function complete():Void - { - if (active && !finished){ - _timeCounter = 0; - _loopsCounter++; - - onLoopFinished(); - } - } + public function complete():Void + { + if (active && !finished) + { + _timeCounter = 0; + _loopsCounter++; + + onLoopFinished(); + if (_loopsCounter == loops) + { + cancel(); + } + } + } @:allow(flixel.util.FlxTimerManager) function onLoopFinished():Void From 8e0032b66ffd7c8e6e820efe670b572a39664e0c Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Thu, 16 Apr 2026 22:14:30 -0700 Subject: [PATCH 6/9] Add completeLoops function. Small function, allows you to rapidly iterate through all remaining loops in a timer, and gracefully exits. ...also reformats complete() a little bit, it was bugging me. --- flixel/util/FlxTimer.hx | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 1811b8e6e7..8d6d2c306f 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -219,10 +219,10 @@ class FlxTimer implements IFlxDestroyable } } } - - /** - * Ends a loop early and calls onComplete(), regardless of how much time is left. - */ + + /** + * Ends a loop early and calls onComplete(), regardless of how much time is left. + */ public function complete():Void { if (active && !finished) @@ -231,9 +231,26 @@ class FlxTimer implements IFlxDestroyable _loopsCounter++; onLoopFinished(); - if (_loopsCounter == loops) + } + } + + /** + * Quickly iterates through all remaining loops. + */ + public function completeLoops():Void + { + while (!finished) + { + if (loops > 0 && (_loopsCounter >= loops)) + { + finished = true; + } + else { - cancel(); + _timeCounter = 0; + _loopsCounter++; + + onLoopFinished(); } } } From a1e2267493fa1589b4077bbabc0869688ea39a38 Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Thu, 16 Apr 2026 22:21:02 -0700 Subject: [PATCH 7/9] Check to see if we've hit our last loop. I think I accidentally deleted this in the last commit. --- flixel/util/FlxTimer.hx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 8d6d2c306f..8cda5965b5 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -231,6 +231,11 @@ class FlxTimer implements IFlxDestroyable _loopsCounter++; onLoopFinished(); + + if (_loopsCounter >= loops) + { + finished = true; + } } } From 278d81efc8cca252293505d264f3833ccaec39fb Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Thu, 16 Apr 2026 22:24:18 -0700 Subject: [PATCH 8/9] Prevent finishing an infinite timer with complete(). --- flixel/util/FlxTimer.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 8cda5965b5..62c10f195a 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -232,7 +232,7 @@ class FlxTimer implements IFlxDestroyable onLoopFinished(); - if (_loopsCounter >= loops) + if (loops > 0 && (_loopsCounter >= loops)) { finished = true; } From be75d5064ccfbb0395c733e8ffca3a499fe8f444 Mon Sep 17 00:00:00 2001 From: Vulpicula <57735830+Vulpicula@users.noreply.github.com> Date: Thu, 16 Apr 2026 22:25:24 -0700 Subject: [PATCH 9/9] Prevent completeLoops from running on an infinite timer, as that'll softlock everything. --- flixel/util/FlxTimer.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flixel/util/FlxTimer.hx b/flixel/util/FlxTimer.hx index 62c10f195a..447165ea27 100644 --- a/flixel/util/FlxTimer.hx +++ b/flixel/util/FlxTimer.hx @@ -244,9 +244,9 @@ class FlxTimer implements IFlxDestroyable */ public function completeLoops():Void { - while (!finished) + while (!finished && loops > 0) { - if (loops > 0 && (_loopsCounter >= loops)) + if (_loopsCounter >= loops) { finished = true; }