This is a quick tutorial for making a heart bar, like those on the Legend of Zelda games. When you’re done, you should have something similar to this:

Step #1: Setting up the Scene
Go ahead and add a empty (called “HEALTH_DEBUG”), and a plane.
Step #2: Scripts
There are two scripts:
healthScript:
import GameLogic
cont = GameLogic.getCurrentController()
own = cont.getOwner()
if own.healthMax >= 10:
own.healthMax = 10
elif own.healthMax < 0:
own.healthMax = 0
if own.health > own.healthMax:
own.health = own.healthMax
elif own.health <=0:
own.health = 0
own.gameOver = 1
else:
own.gameOver = 0
visible:
import GameLogic
cont = GameLogic.getCurrentController()
own = cont.getOwner()
act = cont.getActuator("visible")
true = 1
false = 0
if own.health >= own.number:
act.set(true)
elif own.health <= own.number:
act.set(true)
GameLogic.addActiveActuator(act, true)
Step #3: Setting up LogicBricks
Select the empty and make your logic bricks to look like this:
Now, select the plane, and make the logic bricks look like this:
Step #4: Making the Hearts work
Copy The plane and paste 10 of them in the way you want the hearts aligned, then edit each one’s “number” property. We want the number properties to go from 1, and build up to 10. I have it so that number 1 is on the left (in a row), and 10 is on the rightmost. If you don’t know what I’m talking about, take a look at the .Blend. This is all you have to do here
Step #5: Texturing & Testing
Now, all you have to do is to texture the planes, and test it (P). If it works, then you have successfuly completed this tutorial, if not, then take a look at my working example, and compare what I have with what you have.
.Blend


April 8, 2009 at 6:41 pm
hm nice tut again
but now im having problems with the texture, the alpha
i have a heart, with white background, but when i use it, and set alpha on, then u can still see the white
and when i use add, then u cant see the whtite, but when testing the game, u see blue…
December 7, 2009 at 7:52 pm
The problem is probably that you’re lacking an alpha channel on the image. If you don’t know how to add an alpha channel, be sure to find a tutorial for adding an alpha channel in the program you use.