From 7ce3eabd17eb918ce326cf401e1e43cd80f62084 Mon Sep 17 00:00:00 2001 From: Sword352 Date: Wed, 8 May 2024 07:35:46 +0200 Subject: [PATCH] Better character animation offsets handling. --- source/funkin/play/character/BaseCharacter.hx | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/source/funkin/play/character/BaseCharacter.hx b/source/funkin/play/character/BaseCharacter.hx index 2796f8123..cb9d5ae3f 100644 --- a/source/funkin/play/character/BaseCharacter.hx +++ b/source/funkin/play/character/BaseCharacter.hx @@ -1,6 +1,7 @@ package funkin.play.character; import flixel.math.FlxPoint; +import flixel.FlxCamera; import funkin.modding.events.ScriptEvent; import funkin.play.character.CharacterData.CharacterDataParser; import funkin.play.character.CharacterData.CharacterRenderType; @@ -118,19 +119,17 @@ class BaseCharacter extends Bopper */ public var cameraFocusPoint(default, null):FlxPoint = new FlxPoint(0, 0); + /** + * Defines the animation offset. + */ + public var animOffset:FlxPoint = FlxPoint.get(); + override function set_animOffsets(value:Array):Array { if (animOffsets == null) value = [0, 0]; if ((animOffsets[0] == value[0]) && (animOffsets[1] == value[1])) return value; - // Make sure animOffets are halved when scale is 0.5. - var xDiff = (animOffsets[0] * this.scale.x / (this.isPixel ? 6 : 1)) - value[0]; - var yDiff = (animOffsets[1] * this.scale.y / (this.isPixel ? 6 : 1)) - value[1]; - - // Call the super function so that camera focus point is not affected. - super.set_x(this.x + xDiff); - super.set_y(this.y + yDiff); - + animOffset.set(value[0], value[1]); return animOffsets = value; } @@ -570,11 +569,25 @@ class BaseCharacter extends Bopper } } + // override getScreenPosition (used by FlxSprite's draw method) to account for animation offsets. + override function getScreenPosition(?result:FlxPoint, ?camera:FlxCamera):FlxPoint + { + var output:FlxPoint = super.getScreenPosition(result, camera); + output -= animOffset; + return output; + } + public override function onDestroy(event:ScriptEvent):Void { this.characterType = OTHER; } + override function destroy():Void + { + animOffset = flixel.util.FlxDestroyUtil.put(animOffset); + super.destroy(); + } + /** * Play the appropriate singing animation, for the given note direction. * @param dir The direction of the note.