From 7ce3eabd17eb918ce326cf401e1e43cd80f62084 Mon Sep 17 00:00:00 2001
From: Sword352 <sword352email@gmail.com>
Date: Wed, 8 May 2024 07:35:46 +0200
Subject: [PATCH 1/3] 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<Float>):Array<Float>
   {
     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.

From dd86934712276f136193033237cb15095cc0e787 Mon Sep 17 00:00:00 2001
From: Sword352 <sword352email@gmail.com>
Date: Wed, 8 May 2024 09:22:49 +0200
Subject: [PATCH 2/3] did the requested changes

---
 source/funkin/play/character/BaseCharacter.hx | 29 -------------------
 source/funkin/play/stage/Bopper.hx            | 27 +++++++++++++----
 2 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/source/funkin/play/character/BaseCharacter.hx b/source/funkin/play/character/BaseCharacter.hx
index cb9d5ae3f..eee7d15a2 100644
--- a/source/funkin/play/character/BaseCharacter.hx
+++ b/source/funkin/play/character/BaseCharacter.hx
@@ -1,7 +1,6 @@
 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;
@@ -119,20 +118,6 @@ 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<Float>):Array<Float>
-  {
-    if (animOffsets == null) value = [0, 0];
-    if ((animOffsets[0] == value[0]) && (animOffsets[1] == value[1])) return value;
-
-    animOffset.set(value[0], value[1]);
-    return animOffsets = value;
-  }
-
   /**
    * If the x position changes, other than via changing the animation offset,
    *  then we need to update the camera focus point.
@@ -569,25 +554,11 @@ 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.
diff --git a/source/funkin/play/stage/Bopper.hx b/source/funkin/play/stage/Bopper.hx
index 262aff7bc..141a85c8f 100644
--- a/source/funkin/play/stage/Bopper.hx
+++ b/source/funkin/play/stage/Bopper.hx
@@ -1,6 +1,7 @@
 package funkin.play.stage;
 
 import flixel.FlxSprite;
+import flixel.FlxCamera;
 import flixel.math.FlxPoint;
 import flixel.util.FlxTimer;
 import funkin.modding.IScriptedClass.IPlayStateScriptedClass;
@@ -67,6 +68,11 @@ class Bopper extends StageProp implements IPlayStateScriptedClass
     return value;
   }
 
+  /**
+   * Internally used to define the animation offsets to apply.
+   */
+  var _currentAnimOffset:FlxPoint = FlxPoint.get();
+
   /**
    * The offset of the character relative to the position specified by the stage.
    */
@@ -95,12 +101,7 @@ class Bopper extends StageProp implements IPlayStateScriptedClass
     if (animOffsets == null) animOffsets = [0, 0];
     if ((animOffsets[0] == value[0]) && (animOffsets[1] == value[1])) return value;
 
-    var xDiff = animOffsets[0] - value[0];
-    var yDiff = animOffsets[1] - value[1];
-
-    this.x += xDiff;
-    this.y += yDiff;
-
+    _currentAnimOffset.set(value[0], value[1]);
     return animOffsets = value;
   }
 
@@ -349,6 +350,20 @@ class Bopper extends StageProp implements IPlayStateScriptedClass
     return this.animation.curAnim.name;
   }
 
+  // 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 -= _currentAnimOffset;
+    return output;
+  }
+
+  override function destroy():Void
+  {
+    _currentAnimOffset = flixel.util.FlxDestroyUtil.put(_currentAnimOffset);
+    super.destroy();
+  }
+
   public function onPause(event:PauseScriptEvent) {}
 
   public function onResume(event:ScriptEvent) {}

From f6334fb30b12b44635a9574587f7689d2f3beb28 Mon Sep 17 00:00:00 2001
From: Sword352 <sword352email@gmail.com>
Date: Wed, 8 May 2024 22:18:41 +0200
Subject: [PATCH 3/3] Use `animOffsets` directly.

---
 source/funkin/play/stage/Bopper.hx | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

diff --git a/source/funkin/play/stage/Bopper.hx b/source/funkin/play/stage/Bopper.hx
index 141a85c8f..5485edb3e 100644
--- a/source/funkin/play/stage/Bopper.hx
+++ b/source/funkin/play/stage/Bopper.hx
@@ -68,11 +68,6 @@ class Bopper extends StageProp implements IPlayStateScriptedClass
     return value;
   }
 
-  /**
-   * Internally used to define the animation offsets to apply.
-   */
-  var _currentAnimOffset:FlxPoint = FlxPoint.get();
-
   /**
    * The offset of the character relative to the position specified by the stage.
    */
@@ -101,7 +96,6 @@ class Bopper extends StageProp implements IPlayStateScriptedClass
     if (animOffsets == null) animOffsets = [0, 0];
     if ((animOffsets[0] == value[0]) && (animOffsets[1] == value[1])) return value;
 
-    _currentAnimOffset.set(value[0], value[1]);
     return animOffsets = value;
   }
 
@@ -354,16 +348,11 @@ class Bopper extends StageProp implements IPlayStateScriptedClass
   override function getScreenPosition(?result:FlxPoint, ?camera:FlxCamera):FlxPoint
   {
     var output:FlxPoint = super.getScreenPosition(result, camera);
-    output -= _currentAnimOffset;
+    output.x -= animOffsets[0];
+    output.y -= animOffsets[1];
     return output;
   }
 
-  override function destroy():Void
-  {
-    _currentAnimOffset = flixel.util.FlxDestroyUtil.put(_currentAnimOffset);
-    super.destroy();
-  }
-
   public function onPause(event:PauseScriptEvent) {}
 
   public function onResume(event:ScriptEvent) {}