I have a top down zombie shooter thing going on and I have an odd way from an example to display a health bar. The code goes like so:
private function createLives():Void
{
BaseLifeText = new FlxText(4, 28, 220, "Base Health: ", 12);
BaseLifeText.color = 0xffFFFFFF;
guiGroup.add(BaseLifeText);
for (i in 0...9) {
var cur:Int = lifeGroup.length + 1;
//Start Trick
var colnum:Int = cur;
var xPos:Float = (BaseLifeText.x + 96) + 14 * (colnum - 1);
//End Trick
life = new FlxSprite(xPos, 34,"assets/BaseHealth.png");
lifeGroup.add(life);
}
}
While this is haxe/haxeflixel, I've seen this trick one other time in as3, only done on the draw call. The above trick instead of just displaying one sprite, displays 9. Is there a name for this specific trick?
Part 2 Pertaining to the trick above, I'm also trying to add a collectable that will heal the Base. However, I'm only successful in adding it numerically. I'm doing this:
private function collectCoolant(player:FlxObject, cooler:Coolant):Void
{
cooler.kill();
var cur:Int = lifeGroup.length + 1;
lives ++;
life.x += 14 * cur;
lifeGroup.length + 1;
}
It adds to the life of the the thing, but it doesn't do it graphically like when it's created. Using this system how can I restore health to the thing graphically?