1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-02 03:34:54 +00:00
Funkin/source/HealthIcon.hx

65 lines
1.2 KiB
Haxe
Raw Normal View History

2020-12-24 23:24:11 +00:00
package;
import flixel.FlxSprite;
2021-03-19 01:08:44 +00:00
using StringTools;
2020-12-24 23:24:11 +00:00
class HealthIcon extends FlxSprite
{
2021-03-01 23:59:51 +00:00
/**
* Used for FreeplayState! If you use it elsewhere, prob gonna annoying
*/
public var sprTracker:FlxSprite;
var char:String = '';
2021-03-19 01:08:44 +00:00
var isPlayer:Bool = false;
2020-12-24 23:24:11 +00:00
public function new(char:String = 'bf', isPlayer:Bool = false)
{
super();
2021-03-19 01:08:44 +00:00
this.isPlayer = isPlayer;
changeIcon(char);
2020-12-24 23:24:11 +00:00
antialiasing = true;
scrollFactor.set();
}
2021-03-01 23:59:51 +00:00
2021-03-19 01:08:44 +00:00
public var isOldIcon:Bool = false;
public function swapOldIcon():Void
{
isOldIcon = !isOldIcon;
if (isOldIcon)
changeIcon('bf-old');
2021-03-19 01:08:44 +00:00
else
changeIcon('bf');
2021-03-19 01:08:44 +00:00
}
public function changeIcon(newChar:String):Void
2021-03-19 01:08:44 +00:00
{
if (newChar != 'bf-pixel' && newChar != 'bf-old')
newChar = newChar.split('-')[0].trim();
if (newChar != char)
2021-03-19 04:03:29 +00:00
{
if (animation.getByName(newChar) == null)
{
loadGraphic(Paths.image('icons/icon-' + newChar), true, 150, 150);
animation.add(newChar, [0, 1], 0, false, isPlayer);
}
animation.play(newChar);
char = newChar;
2021-03-19 04:03:29 +00:00
}
2021-03-19 01:08:44 +00:00
}
2021-03-01 23:59:51 +00:00
override function update(elapsed:Float)
{
super.update(elapsed);
if (sprTracker != null)
setPosition(sprTracker.x + sprTracker.width + 10, sprTracker.y - 30);
}
2020-12-24 23:24:11 +00:00
}