diff --git a/source/funkin/game/HealthIcon.hx b/source/funkin/game/HealthIcon.hx index 9fd88170..d55bf14b 100644 --- a/source/funkin/game/HealthIcon.hx +++ b/source/funkin/game/HealthIcon.hx @@ -8,14 +8,21 @@ class HealthIcon extends FlxSprite */ public var sprTracker:FlxSprite; + /** + * The currently showing icon + */ + public var curCharacter:String = null; + + /** + * If the character is for the player + */ + public var isPlayer:Bool; + /** * Health steps in this format: * Min Percentage => Frame Index */ - public var healthSteps:Map = [ - 0 => 1, // losing icon - 20 => 0, // normal icon - ]; + public var healthSteps:Map = null; /** * Helper for HScript who can't make maps @@ -40,21 +47,34 @@ class HealthIcon extends FlxSprite { super(); health = 0.5; - var path = Paths.image('icons/$char'); - if (!Assets.exists(path)) path = Paths.image('icons/face'); - - loadGraphic(path, true, 150, 150); - - animation.add(char, [for(i in 0...frames.frames.length) i], 0, false, isPlayer); - antialiasing = true; - animation.play(char); - - if (frames.frames.length >= 3) - healthSteps[80] = 2; // winning icon + this.isPlayer = isPlayer; + setIcon(char); scrollFactor.set(); } + public function setIcon(char:String, width:Int = 150, height:Int = 150) { + if(curCharacter != char || this.width != width || this.height != height) { + curCharacter = char; + var path = Paths.image('icons/$char'); + if (!Assets.exists(path)) path = Paths.image('icons/face'); + + loadGraphic(path, true, width, height); + + animation.add(char, [for(i in 0...frames.frames.length) i], 0, false, isPlayer); + antialiasing = true; + animation.play(char); + + healthSteps = [ + 0 => 1, // losing icon + 20 => 0, // normal icon + ]; + + if (frames.frames.length >= 3) + healthSteps[80] = 2; // winning icon + } + } + override function update(elapsed:Float) { super.update(elapsed);