Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better offsets handling for gameplay props. #2310

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions source/funkin/play/character/BaseCharacter.hx
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,6 @@ class BaseCharacter extends Bopper
*/
public var cameraFocusPoint(default, null):FlxPoint = new FlxPoint(0, 0);

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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give an explanation as to how/why your implementation doesn't require this custom scale logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I'm not quite sure why it was there in the first place.
People says this somewhat makes the character progressively "fly" because scale isn't applied on value.
If this was meant for week 6 then I don't see how that has an effect as it just scales then divide by 6. However if this is meant to normalize the offset by scale (which I thought funkin doesn't) then I can re-implement that back.

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);

return animOffsets = value;
}

/**
* If the x position changes, other than via changing the animation offset,
* then we need to update the camera focus point.
Expand Down
16 changes: 10 additions & 6 deletions source/funkin/play/stage/Bopper.hx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -95,12 +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;

var xDiff = animOffsets[0] - value[0];
var yDiff = animOffsets[1] - value[1];

this.x += xDiff;
this.y += yDiff;

return animOffsets = value;
}

Expand Down Expand Up @@ -349,6 +344,15 @@ 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.x -= animOffsets[0];
output.y -= animOffsets[1];
return output;
}

public function onPause(event:PauseScriptEvent) {}

public function onResume(event:ScriptEvent) {}
Expand Down
Loading