diff --git a/source/objects/HealthIcon.hx b/source/objects/HealthIcon.hx index fedbd384a2c..a0f33ce5360 100644 --- a/source/objects/HealthIcon.hx +++ b/source/objects/HealthIcon.hx @@ -34,6 +34,17 @@ class HealthIcon extends FlxSprite } private var iconSize:Int = 0; + /** + * An index which decides which frame of the icon to use. + */ + @:isVar public var iconIndex(get, set):Int; + public function get_iconIndex() { + return iconIndex = animation?.curAnim.curFrame ?? 0; + } + public function set_iconIndex(i:Int):Int { + return iconIndex = animation.curAnim.curFrame = (i % iconSize); + } + private var iconOffsets:Array = [0, 0]; public function changeIcon(char:String, ?allowGPU:Bool = true) { if(this.char != char) { diff --git a/source/states/PlayState.hx b/source/states/PlayState.hx index 463564a6336..3e9c3c8f3e4 100644 --- a/source/states/PlayState.hx +++ b/source/states/PlayState.hx @@ -1844,8 +1844,8 @@ class PlayState extends MusicBeatState var newPercent:Null = FlxMath.remapToRange(FlxMath.bound(healthBar.valueFunction(), healthBar.bounds.min, healthBar.bounds.max), healthBar.bounds.min, healthBar.bounds.max, 0, 100); healthBar.percent = (newPercent != null ? newPercent : 0); - iconP1.animation.curAnim.curFrame = (healthBar.percent < 20) ? 1 : 0; //If health is under 20%, change player icon to frame 1 (losing icon), otherwise, frame 0 (normal) - iconP2.animation.curAnim.curFrame = (healthBar.percent > 80) ? 1 : 0; //If health is over 80%, change opponent icon to frame 1 (losing icon), otherwise, frame 0 (normal) + iconP1.iconIndex = (healthBar.percent < 20) ? 1 : 0; //If health is under 20%, change player icon to frame 1 (losing icon), otherwise, frame 0 (normal) + iconP2.iconIndex = (healthBar.percent > 80) ? 1 : 0; //If health is over 80%, change opponent icon to frame 1 (losing icon), otherwise, frame 0 (normal) return health; }