Health Bar help

5 posts

Flag Post

Hey. In a game I am making in actionscript 2, I am trying to make a health meter that uses individual dots to count for each “health point”. Does anyone know how I can make it to where after each damage the meter looses one dot? Thanks

 
Flag Post

You can either use differents frames in the health var and give one less dot in each frame or you can store all the dots in one array.
Example code in ActionScript3 (I don’t know AS2, sorry, I hope you can translate it) :

var maxLife:int = 10;
var currentLife:int = maxLife;
var i:int = 0;
var lifeDots:Array = new Array();
var lifeDot:LifeDot;
var lifeDotX = 10;
while (i < maxLife) {
	lifeDot = new LifeDot()
	lifeDot.x = lifeDotX;
	lifeDot.y = 20;
	lifeDotX += lifeDot.width;
	addChild(lifeDot);
	lifeDots[i] = lifeDot;
	i++
}
function loseLife() { 
	currentLife--
	removeChild(lifeDots[currentLife])
	
	
}

 
Flag Post

Instead of removeChild(lifeDots[currentLife])
use lifeDots[currentLife].visible=false;

that way, it’ll still be there if you do something like pick up a health pack (just set visible to true)

 
Flag Post

You can make a variable for health as usual, and make a movieclip with a certain number of dots on each frame (1 dot on frame 1, 2 dots on frame 2, etc), and have the movieclip go to the right frame —

healthMeter.gotoAndStop(health);

That’s probably the easiest way to do it.

 
Flag Post

You can also use the normal layer mask way, only it stops at set intervals instead of any floating point value.