Set Icon on icons

This commit is contained in:
NeeEoo
2024-03-15 02:39:35 +01:00
parent a548c74c9e
commit d633d9b582
+35 -15
View File
@@ -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<Int, Int> = [
0 => 1, // losing icon
20 => 0, // normal icon
];
public var healthSteps:Map<Int, Int> = 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);