Skip to content

Commit 2a700b6

Browse files
committed
FunkinSprite's copyFrom working for FlxSprite too
1 parent 6c0b245 commit 2a700b6

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

source/funkin/backend/FunkinSprite.hx

+17-7
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,34 @@ class FunkinSprite extends FlxSkewedSprite implements IBeatReceiver implements I
7272
moves = false;
7373
}
7474

75-
public static function copyFrom(source:FunkinSprite)
75+
/**
76+
* Gets the graphics and copies other properties from another sprite (Works both for `FlxSprite` and `FunkinSprite`!).
77+
*/
78+
public static function copyFrom(source:FlxSprite):FunkinSprite
7679
{
7780
var spr = new FunkinSprite();
81+
var casted:FunkinSprite = null;
82+
if (source is FunkinSprite)
83+
casted = cast source;
84+
7885
@:privateAccess {
7986
spr.setPosition(source.x, source.y);
8087
spr.frames = source.frames;
81-
if (source.animateAtlas != null && source.atlasPath != null)
82-
spr.loadSprite(source.atlasPath);
88+
if (casted != null && casted.animateAtlas != null && casted.atlasPath != null)
89+
spr.loadSprite(casted.atlasPath);
8390
spr.animation.copyFrom(source.animation);
8491
spr.visible = source.visible;
8592
spr.alpha = source.alpha;
8693
spr.antialiasing = source.antialiasing;
8794
spr.scale.set(source.scale.x, source.scale.y);
8895
spr.scrollFactor.set(source.scrollFactor.x, source.scrollFactor.y);
89-
spr.skew.set(source.skew.x, source.skew.y);
90-
spr.transformMatrix = source.transformMatrix;
91-
spr.matrixExposed = source.matrixExposed;
92-
spr.animOffsets = source.animOffsets.copy();
96+
97+
if (casted != null) {
98+
spr.skew.set(casted.skew.x, casted.skew.y);
99+
spr.transformMatrix = casted.transformMatrix;
100+
spr.matrixExposed = casted.matrixExposed;
101+
spr.animOffsets = casted.animOffsets.copy();
102+
}
93103
}
94104
return spr;
95105
}

0 commit comments

Comments
 (0)