From 9209bac02c1f89431876dcda56eb068c6cae381c Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Wed, 14 Feb 2024 03:27:34 -0500 Subject: [PATCH] Port improved AtlasSprite from char-select-rebase --- .../graphics/adobeanimate/FlxAtlasSprite.hx | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx b/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx index ae7a5708c..fe024e2f5 100644 --- a/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx +++ b/source/funkin/graphics/adobeanimate/FlxAtlasSprite.hx @@ -18,7 +18,7 @@ class FlxAtlasSprite extends FlxAnimate // ?OnComplete:Void -> Void, ShowPivot: #if debug false #else false #end, Antialiasing: true, - ScrollFactor: new FlxPoint(1, 1), + ScrollFactor: null, // Offset: new FlxPoint(0, 0), // This is just FlxSprite.offset }; @@ -55,8 +55,8 @@ class FlxAtlasSprite extends FlxAnimate */ public function listAnimations():Array { - // return this.anim.getFrameLabels(); - return [""]; + return this.anim.getFrameLabels(); + // return [""]; } /** @@ -82,8 +82,10 @@ class FlxAtlasSprite extends FlxAnimate * @param restart Whether to restart the animation if it is already playing. * @param ignoreOther Whether to ignore all other animation inputs, until this one is done playing */ - public function playAnimation(id:String, restart:Bool = false, ignoreOther:Bool = false):Void + public function playAnimation(id:String, restart:Bool = false, ignoreOther:Bool = false, ?loop:Bool = false):Void { + if (loop == null) loop = false; + // Skip if not allowed to play animations. if ((!canPlayOtherAnims && !ignoreOther)) return; @@ -110,15 +112,14 @@ class FlxAtlasSprite extends FlxAnimate return; } - // Stop the current animation if it is playing. - // This includes removing existing frame callbacks. - if (this.currentAnimation != null) this.stopAnimation(); - - // Add a callback to ensure `onAnimationFinish` is dispatched. - addFrameCallback(getNextFrameLabel(id), function() { - trace('Animation finished: ' + id); - onAnimationFinish.dispatch(id); - }); + anim.callback = function(_, frame:Int) { + if (frame == (anim.getFrameLabel(id).duration - 1) + anim.getFrameLabel(id).index) + { + if (loop) playAnimation(id, true, false, true); + else + onAnimationFinish.dispatch(id); + } + }; // Prevent other animations from playing if `ignoreOther` is true. if (ignoreOther) canPlayOtherAnims = false; @@ -128,6 +129,11 @@ class FlxAtlasSprite extends FlxAnimate this.currentAnimation = id; } + override public function update(elapsed:Float) + { + super.update(elapsed); + } + /** * Stops the current animation. */