did the requested changes

This commit is contained in:
Sword352 2024-05-08 09:22:49 +02:00
parent 7ce3eabd17
commit dd86934712
2 changed files with 21 additions and 35 deletions

View file

@ -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.

View file

@ -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) {}