Game Development Community

Health GUI Help

by John Eric Miller · in Torque Game Engine · 07/09/2005 (4:32 pm) · 11 replies

I am trying to figure out how I could go about creating a health GUI that displayed icons for each unit of health ala Zelda for example. Zelda has a system where you have 3 hearts and as you get hit the hearts change color but you can aquire more heart "containers" so instead of 3 you have 4. I would like to create a similar system. First I need to know how to go about displaying 2d images dynamically in a GUI. Can anyone give me any pointers for doing this. I would like to release this as a resource to the community.

Thanks!

#1
07/09/2005 (4:36 pm)
Something like This maybe
#2
07/09/2005 (7:19 pm)
I don't want an energy bar I want a series of images for each point of health. how can I dynamically display a series of bitmaps in a row in a gui control. Let say the player can be hit 5 times before he dies. I would like to display 5 hearts as a helth indicator and when he gets hit the hearts change to a darker color until all the hearts are dark and the player dies. I want it to be dynamic so the player can get more hearts during the game.

Thanks!
#3
07/09/2005 (10:58 pm)
Simplest would be to change the GuiHealthBar Hud to use a bitmap of a heart, instead of a drawing of a red square.
#4
07/10/2005 (12:20 am)
You could include multiple health variables for the main player, with each one being a heart (heart = 1 health). Have the attacks of enemies equal something like .5, 1, or 2 damage (or health).

Now, modify it so that if you exaust one heart, it will move to the next variable and start subtracting from that... I'm not a programmer, so I'm sorry I couldn't be of more help.
#5
07/10/2005 (5:29 am)
Dreamer, I want to display more than one heart. I want to display 1 heart for each point of health. Your dynamic GUI stuff gave me some ideas. I will basically need 2 variables max health and current health. I will also need 2 heart graphics one red and one dark red. I have a few questions though. How do I determine if a GUI control exists and then how would I go about deleting it and then rebuild it? Is this simple to do? I need to create a function that deletes and rebuilds the HUD everytime the player is injured or gets a new Heart container. I appreciate the help!
#6
07/10/2005 (6:14 am)
You could simply do it in script and read how much health you got, then use setVisible(bool); to show or hide the hearts.
#7
07/10/2005 (11:07 am)
Thanks Stefan!

I thought about that but I would like to show the max hearts as well as the current amount. I guess I could go ahead and setup a predefined amount of heart slots and just change the bitmap. Can I set a bitmap to blank for the slots not being used? Is there a way to loop through sub gui controls?
#8
07/10/2005 (11:32 am)
The slots not being used wouldn't need to be painted in any other way, just use SetVisible(0); on them to hide them, or make the bitmap transparent. You can do it in a million ways, and just add one heart for every new one you'd want.
#9
07/10/2005 (12:48 pm)
Sounds good to me! I appreciate the advice.
#10
07/10/2005 (3:50 pm)
Ok, I created my heart bitmaps in the playgui.gui but I can;t access them. I typed Heart6.SetVisible(1); and got this error ==>Heart6.SetVisible(1);
(0): Unable to find object: 'Heart6' attempting to call function 'setVisible'

Here is the code I added to playgui

// Heart HUD
new GuiBitmapCtrl(Heart1) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "620 5";
extent = "15 15";
minExtent = "15 15";
visible = "1";
helpTag = "0";
bitmap = "./HeartLight25.png";
wrap = "0";
};
new GuiBitmapCtrl(Heart2) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "600 5";
extent = "15 15";
minExtent = "15 15";
visible = "1";
helpTag = "0";
bitmap = "./HeartLight25.png";
wrap = "0";
};
new GuiBitmapCtrl(Heart3) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "580 5";
extent = "15 15";
minExtent = "15 15";
visible = "1";
helpTag = "0";
bitmap = "./HeartLight25.png";
wrap = "0";
};
new GuiBitmapCtrl(Heart4) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "560 5";
extent = "15 15";
minExtent = "15 15";
visible = "1";
helpTag = "0";
bitmap = "./HeartLight25.png";
wrap = "0";
};
new GuiBitmapCtrl(Heart5) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "540 5";
extent = "15 15";
minExtent = "15 15";
visible = "1";
helpTag = "0";
bitmap = "./HeartDark25.png";
wrap = "0";
};
new GuiBitmapCtrl(Heart6) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "520 5";
extent = "15 15";
minExtent = "15 15";
visible = "0";
helpTag = "0";
bitmap = "./HeartDark25.png";
wrap = "0";
};
#11
03/03/2006 (9:24 am)
Try this. Maybe it help you.

http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7837