how to make a more professional heart bar

i know how to make a normal life bar but i have difficulties on making a life bar like in legend of zelda, please help

Just make a python code which based on where you want the hearths to start, get that position, and add a single hearth graphic one after the other in the screen width until a horizontal hearths limit is reached(you have to count how many were already added), if that limit is reached the ‘adding’ would return to the original position, but go below at the screen height. Then you would have yourself two rows of hearths or just one, depending of how many hearths you have.

I would use Moguri BGUI for that.

You simply can use a Bitmap font object. Replace one of the characters with a heart. Then you can simply set a property with the according string.


1 heart:“o” 3 hearth:“ooo”

when replacing o with an hearth texture

i’m a beginner i gust started blender few weeks ago so i’m no t able to script or use python,if you have time could you please make an example of what you have written

does not work

this is brilleint i never thought of this

i did this once and it was vary complicated. what i did is i had a background behind the hearts with the hearts on different layers on the z axis. then when i wanted to subtract a heart i moved the background up one unit. givving the illusion of a heart dissapering. it worked great on an overlay with a othegraphic camera. not vary efficent though.

i just might learn how to use python because i tried with logic bricks but there are some bugs and it looks so unreal

i tried and with a tutorial i made this but i have problems with the script

Example.blend (633 KB)
Here’s my example.

thank you but one thing when i start the game the textures of the planes doesn’t show up

Press the + and - numpad keys

Here’s a better example. Change the value of “hp” on the control empty.
Example (1).blend (424 KB)

My thoughts as well. I did it the hard way with actual heart objects for each heart. XP It worked, but this method sounds far easier. Though you would need a bitmap font sheet to start with.

@agoose77 - Nice example. A bit complex, but it works. It’d be nice if you could more easily add hearts, since you have to add them in Blender for them to work (i.e. you can’t ‘expand’ your heart count in-game). It wouldn’t be hard to add, though.

life: ███████████████░
mana: ████████░░░░░░░

:heavy_check_mark::heart::heart::heart::heart: ★★★✩✩ ♂ ♀


why this get()
health = own.get(“hp”, 3)
which is ugly and probably also more slow?

    for i in own.children:
        if i["hp"]<=own["hp"]:

is this get() which make confusion :stuck_out_tongue:

Because if the parent object doesn’t have a hp property, it won’t die and throw a ton of errors.
Secondly, if statements are expensive, and the i[‘hp’] > own[‘hp’] returns a boolean anyway.

we can make better

this is more robust

import bge

    def control(cont):
        own = cont.owner

            L=[i for i in own.children if "hp" in i]
            for i in L:
            L=[i for i in D]
            L.sort(key=lambda k : k[hp])
            for i in range(len(D)):
                if L[i][hp]<=own[hp]:

“if statements are expensive”

that is not true…is a leggend

…get() expect a error, is a kind of try/except , usually that more slow than one thing which can get a error…

No, this is true. An IF statement will be slower than using the boolean return.

Compare these:

variable = 10

if variable == 10:
    output = True
    output = True

output = variable == 10

In addition, always catch an Exception where possible. In your case any coding error would pass silently.

Here is a comparison of the Exception against get(). I will not use the “in” method, because it is marginally faster, but more obfuscated code.