Skip to content

Commit 59603bf

Browse files
TechnikTilCrusherNotDrip
authored andcommitted
Let loadTexture scale regular textures.
- Rename `rectWidth`/`rectHeight` to just `width`/`height` - Make `width` and `height` use `setGraphicSize` so that it will work on normal textures. Signed-off-by: TechnikTil <techniktil@tilnotdrip.org>
1 parent 2e54ff1 commit 59603bf

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

src/funkin/objects/FunkinSprite.hx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package funkin.objects;
33
import animate.FlxAnimate;
44
import animate.FlxAnimateFrames;
55
import flixel.animation.FlxAnimation;
6+
import flixel.graphics.FlxGraphic;
67
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
78
import flixel.util.FlxSignal.FlxTypedSignal;
89
import funkin.structures.ObjectStructure;
@@ -30,31 +31,28 @@ class FunkinSprite extends FlxAnimate
3031
super(x, y);
3132
}
3233

33-
override function initVars():Void
34-
{
35-
super.initVars();
36-
}
37-
3834
/**
3935
* Loads or creates a texture and applies it to this sprite.
40-
* @param path The asset path. (If `path` starts with a **#** then a color will be made instead and rectWidth + rectHeight will determine its size.)
41-
* @param rectWidth If the path is a color then how big should it's width be?
42-
* @param rectHeight If the path is a color then how big should it's height be?
36+
* @param path The asset path of the texture.
37+
* @param width What should the width of the sprite be?
38+
* @param height What should the height of the sprite be?
4339
* @return This `FunkinSprite` instance (nice for chaining stuff together, if you're into that).
4440
*/
45-
public function loadTexture(path:String = '#000000', rectWidth:Int = 1, rectHeight:Int = 1):FunkinSprite
41+
public function loadTexture(path:String = '#000000', width:Int = 0, height:Int = 0):FunkinSprite
4642
{
47-
// Regex Check for colors?
48-
if (path.startsWith('#'))
49-
{
50-
loadGraphic(FlxG.bitmap.create(1, 1, FlxColor.fromString(path), false));
51-
scale.set(rectWidth, rectHeight);
52-
updateHitbox();
53-
}
54-
else
55-
{
56-
loadGraphic(Paths.content.imageGraphic(path));
57-
}
43+
var rectColor:Null<FlxColor> = FlxColor.fromString(path);
44+
45+
var graphic:FlxGraphic =
46+
{
47+
if (rectColor != null)
48+
FlxG.bitmap.create(1, 1, rectColor, false);
49+
else
50+
Paths.content.imageGraphic(path);
51+
}
52+
53+
loadGraphic(graphic);
54+
setGraphicSize(width, height);
55+
updateHitbox();
5856

5957
return this;
6058
}

0 commit comments

Comments
 (0)