Skip to content

Commit 81f81f2

Browse files
AbnormalPoofHundrec
authored andcommitted
Fix atlases moving to the wrong place on restart
Bundled with a ton of manual offset fixes and adjustments
1 parent 26dfbde commit 81f81f2

File tree

4 files changed

+14
-38
lines changed

4 files changed

+14
-38
lines changed

source/funkin/play/character/AnimateAtlasCharacter.hx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import funkin.util.assets.FlxAnimationUtil;
55
import funkin.modding.events.ScriptEvent;
66
import funkin.data.animation.AnimationData;
77
import funkin.data.character.CharacterData.CharacterRenderType;
8-
import flixel.math.FlxPoint;
98

109
/**
1110
* An AnimateAtlasCharacter is a Character which is rendered by
@@ -16,8 +15,6 @@ import flixel.math.FlxPoint;
1615
*/
1716
class AnimateAtlasCharacter extends BaseCharacter
1817
{
19-
var originalSizes(default, never):FlxPoint = new FlxPoint(0, 0);
20-
2118
public function new(id:String)
2219
{
2320
super(id, CharacterRenderType.AnimateAtlas);
@@ -43,8 +40,6 @@ class AnimateAtlasCharacter extends BaseCharacter
4340

4441
trace('[ATLASCHAR] Successfully loaded texture atlas for ${characterId} with ${_data.animations.length} animations.');
4542
super.onCreate(event);
46-
47-
originalSizes.set(this.width, this.height);
4843
}
4944

5045
function loadAtlas():Void
@@ -91,16 +86,6 @@ class AnimateAtlasCharacter extends BaseCharacter
9186
trace('[ATLASCHAR] Successfully loaded ${animNames.length} animations for ${characterId}');
9287
}
9388

94-
override function get_width():Float
95-
{
96-
return originalSizes.x;
97-
}
98-
99-
override function get_height():Float
100-
{
101-
return originalSizes.y;
102-
}
103-
10489
/**
10590
* Get the configuration for the texture atlas.
10691
* @return The configuration for the texture atlas.

source/funkin/play/character/BaseCharacter.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,11 @@ class BaseCharacter extends Bopper
318318
}
319319
}
320320

321-
function resetCameraFocusPoint():Void
321+
public function resetCameraFocusPoint():Void
322322
{
323323
// Calculate the camera focus point
324-
var charCenterX = this.x + this.width / 2;
325-
var charCenterY = this.y + this.height / 2;
324+
var charCenterX = this.originalPosition.x + this.width / 2;
325+
var charCenterY = this.originalPosition.y + this.height / 2;
326326
this.cameraFocusPoint = new FlxPoint(charCenterX + _data.cameraOffsets[0], charCenterY + _data.cameraOffsets[1]);
327327
}
328328

source/funkin/play/character/MultiAnimateAtlasCharacter.hx

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import animate.FlxAnimateFrames;
66
import funkin.modding.events.ScriptEvent;
77
import funkin.data.animation.AnimationData;
88
import funkin.data.character.CharacterData.CharacterRenderType;
9-
import flixel.math.FlxPoint;
109

1110
/**
1211
* This render type is the most complex, and is used by characters which use
@@ -18,8 +17,6 @@ import flixel.math.FlxPoint;
1817
*/
1918
class MultiAnimateAtlasCharacter extends BaseCharacter
2019
{
21-
var originalSizes(default, never):FlxPoint = new FlxPoint(0, 0);
22-
2320
public function new(id:String)
2421
{
2522
super(id, CharacterRenderType.MultiAnimateAtlas);
@@ -45,8 +42,6 @@ class MultiAnimateAtlasCharacter extends BaseCharacter
4542

4643
trace('[MULTIATLASCHAR] Successfully loaded texture atlases for ${characterId} with ${_data.animations.length} animations.');
4744
super.onCreate(event);
48-
49-
originalSizes.set(this.width, this.height);
5045
}
5146

5247
function loadAtlases():Void
@@ -117,16 +112,6 @@ class MultiAnimateAtlasCharacter extends BaseCharacter
117112
trace('[MULTIATLASCHAR] Successfully loaded ${animNames.length} animations for ${characterId}');
118113
}
119114

120-
override function get_width():Float
121-
{
122-
return originalSizes.x;
123-
}
124-
125-
override function get_height():Float
126-
{
127-
return originalSizes.y;
128-
}
129-
130115
/**
131116
* Get the configuration for the texture atlas.
132117
* @return The configuration for the texture atlas.

source/funkin/play/stage/Stage.hx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass implements
9898
// Reset positions of characters.
9999
if (getBoyfriend() != null)
100100
{
101-
getBoyfriend().resetCharacter(true);
102101
// Reapply the camera offsets.
103102
var stageCharData:StageDataCharacter = _data.characters.bf;
104103
var finalScale:Float = getBoyfriend().getBaseScale() * stageCharData.scale;
105104
getBoyfriend().setScale(finalScale);
105+
getBoyfriend().resetCharacter(true);
106+
106107
getBoyfriend().cameraFocusPoint.x += stageCharData.cameraOffsets[0];
107108
getBoyfriend().cameraFocusPoint.y += stageCharData.cameraOffsets[1];
108109
}
@@ -112,21 +113,23 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass implements
112113
}
113114
if (getGirlfriend() != null)
114115
{
115-
getGirlfriend().resetCharacter(true);
116116
// Reapply the camera offsets.
117117
var stageCharData:StageDataCharacter = _data.characters.gf;
118118
var finalScale:Float = getGirlfriend().getBaseScale() * stageCharData.scale;
119119
getGirlfriend().setScale(finalScale);
120+
getGirlfriend().resetCharacter(true);
121+
120122
getGirlfriend().cameraFocusPoint.x += stageCharData.cameraOffsets[0];
121123
getGirlfriend().cameraFocusPoint.y += stageCharData.cameraOffsets[1];
122124
}
123125
if (getDad() != null)
124126
{
125-
getDad().resetCharacter(true);
126127
// Reapply the camera offsets.
127128
var stageCharData:StageDataCharacter = _data.characters.dad;
128129
var finalScale:Float = getDad().getBaseScale() * stageCharData.scale;
129130
getDad().setScale(finalScale);
131+
getDad().resetCharacter(true);
132+
130133
getDad().cameraFocusPoint.x += stageCharData.cameraOffsets[0];
131134
getDad().cameraFocusPoint.y += stageCharData.cameraOffsets[1];
132135
}
@@ -446,10 +449,13 @@ class Stage extends FlxSpriteGroup implements IPlayStateScriptedClass implements
446449
character.x = stageCharData.position[0] - character.characterOrigin.x;
447450
character.y = stageCharData.position[1] - character.characterOrigin.y;
448451

449-
character.originalPosition.set(character.x, character.y);
450-
451452
var finalScale = character.getBaseScale() * stageCharData.scale;
452453
character.setScale(finalScale); // Don't use scale.set for characters!
454+
character.originalPosition.set(character.x, character.y);
455+
456+
// Reset the camera focus point to be based on the new original position.
457+
character.resetCameraFocusPoint();
458+
453459
character.cameraFocusPoint.x += stageCharData.cameraOffsets[0];
454460
character.cameraFocusPoint.y += stageCharData.cameraOffsets[1];
455461

0 commit comments

Comments
 (0)