Hud Images to Represent State of Player Health
by Steve Acaster · 02/24/2011 (9:40 am) · 14 comments
We are going to replace the stock HealthHUD (which displays a numerical value for Player Health) with a series of warning Signs that equate to a percentage of Player health. Let's split these into 4 states:
76-100% = Good
51-74% = Okay
26-50% = Caution
01-25% = Danger




We need images for to display so in your favourite 2D art app, make your images 128x64 and save them to (game-> art-> gui-> images). In your project directory, in "game-> art-> gui" make a new folder called "images" and place your four new images there. (The ones that I am using are specially coloured for visibility if the player is colourblind)
Now to Torque3D and we'll start with the GUIs. Open up the Gui Editor in-game (F10).
First up, let's get rid of the standard HealthHud. Rather than delete a stock asset, let's just set it's visibility to false. Uncheck "visibile" and "active" in the Inspector Panel. As far as the player is concerned, the numerical Health display is now off.
Create a new Gui object to hold all of our custom Gui objects inside of, this will also double as the border for the background. (Library-> Images ) and select "GuiBitmapBorderCtrl". Select the Gui tab so we can see our list of Guis again and select the new object. Let's name this "HealthImageHud" and in the "Profile" drop-down menu in the Inspector choose "ChatHudBorderProfile". Save, we're using the stock PlayGui.gui so you don't need to create a new file.
A thick border should have appeared on-screen, right at the top left corner. Move it towards the lower left corner using the position "6 685". We're going to make it similar to the original HealthHud, only longer. Set the "extent" to "144 80". To keep it in place regardless of screen resolution we need to set "horizSizing" to "right" and "vertSizing" to "top". In other words - the areas of the screen that it is AWAY from, NOT closest to. Now it will keep it's position when you change screen resolution. Finally check "isContainer" under "Editing". Now we can move other gui elements inside it.
Next let's fill that blank space inside the border. Create a GuiBitmapCtrl (Library-> Images->). Back in the Gui tab, name this "HealthImageBack". If this new element is not nested underneath "HealthImageHud", drag and drop it on to it. A little arrow will appear next to "HealthImageHud" to show that you can expand/collapse it to view the gui elements nested underneath. Returning to "HealthImageback" in bitmap find and select "hudfill" (game-> core-> art-> gui-> images-> hudfill.png). Set "position" as "8 8" and "extent" to "128 64" so it does not overlap the border.
Considering that this is the perfect size and placement for our set of Player Health state images, let's duplicate it. With "HealthImageBack" selected, In the toolbar menu, select edit and then copy, and then paste. You should now have a new gui element called "HealthImageback1". Rename it "healthGood". Now copy and paste this element another three times, and rename these three copies as "healthOkay", "healthCaution" and "healthDanger". Finally move "HealthImageBack" to the top of this mini-list under "HealthImageHud". Gui displays in order of last to first, so "HeathImageHud" is now at the back and "HealthDanger" is at the front.

Right click -> view image for larger pic
Select "healthGood" and in bitmap find the image you made named "Good". Now uncheck visibility to hide it. Do the same for each of the other three guis which will hold our remaining images, and then hide their visibility. You should now just be able to see our border and background image.
Finally, as our new HealthImageHud is larger than the older one, you'll want to move the "WeaponHud" over a little so that they don't overlap. Select "weaponHud" and set it's "position" to "158 689". Now there should be no conflict. Save and quit, Torque3D.
Scripting time. In your favourite text editor open the file "game->scripts->server->player.cs. Find the function called "Player::updateHealth", and comment out the commandToClient, and add this.
Next in "game->scripts->client->client.cs" we shall make out new CommandToClient.
And now, when the player's health changes in-game, the correct image should show.

76-100% = Good
51-74% = Okay
26-50% = Caution
01-25% = Danger




We need images for to display so in your favourite 2D art app, make your images 128x64 and save them to (game-> art-> gui-> images). In your project directory, in "game-> art-> gui" make a new folder called "images" and place your four new images there. (The ones that I am using are specially coloured for visibility if the player is colourblind)
Now to Torque3D and we'll start with the GUIs. Open up the Gui Editor in-game (F10).
First up, let's get rid of the standard HealthHud. Rather than delete a stock asset, let's just set it's visibility to false. Uncheck "visibile" and "active" in the Inspector Panel. As far as the player is concerned, the numerical Health display is now off.
Create a new Gui object to hold all of our custom Gui objects inside of, this will also double as the border for the background. (Library-> Images ) and select "GuiBitmapBorderCtrl". Select the Gui tab so we can see our list of Guis again and select the new object. Let's name this "HealthImageHud" and in the "Profile" drop-down menu in the Inspector choose "ChatHudBorderProfile". Save, we're using the stock PlayGui.gui so you don't need to create a new file.
A thick border should have appeared on-screen, right at the top left corner. Move it towards the lower left corner using the position "6 685". We're going to make it similar to the original HealthHud, only longer. Set the "extent" to "144 80". To keep it in place regardless of screen resolution we need to set "horizSizing" to "right" and "vertSizing" to "top". In other words - the areas of the screen that it is AWAY from, NOT closest to. Now it will keep it's position when you change screen resolution. Finally check "isContainer" under "Editing". Now we can move other gui elements inside it.
Next let's fill that blank space inside the border. Create a GuiBitmapCtrl (Library-> Images->). Back in the Gui tab, name this "HealthImageBack". If this new element is not nested underneath "HealthImageHud", drag and drop it on to it. A little arrow will appear next to "HealthImageHud" to show that you can expand/collapse it to view the gui elements nested underneath. Returning to "HealthImageback" in bitmap find and select "hudfill" (game-> core-> art-> gui-> images-> hudfill.png). Set "position" as "8 8" and "extent" to "128 64" so it does not overlap the border.
Considering that this is the perfect size and placement for our set of Player Health state images, let's duplicate it. With "HealthImageBack" selected, In the toolbar menu, select edit and then copy, and then paste. You should now have a new gui element called "HealthImageback1". Rename it "healthGood". Now copy and paste this element another three times, and rename these three copies as "healthOkay", "healthCaution" and "healthDanger". Finally move "HealthImageBack" to the top of this mini-list under "HealthImageHud". Gui displays in order of last to first, so "HeathImageHud" is now at the back and "HealthDanger" is at the front.

Right click -> view image for larger pic
Select "healthGood" and in bitmap find the image you made named "Good". Now uncheck visibility to hide it. Do the same for each of the other three guis which will hold our remaining images, and then hide their visibility. You should now just be able to see our border and background image.
Finally, as our new HealthImageHud is larger than the older one, you'll want to move the "WeaponHud" over a little so that they don't overlap. Select "weaponHud" and set it's "position" to "158 689". Now there should be no conflict. Save and quit, Torque3D.
Scripting time. In your favourite text editor open the file "game->scripts->server->player.cs. Find the function called "Player::updateHealth", and comment out the commandToClient, and add this.
commandToClient(%player.client, 'setImageHealthHUD', %curHealth); //commandToClient(%player.client, 'setNumericalHealthHUD', %curHealth);Save.
Next in "game->scripts->client->client.cs" we shall make out new CommandToClient.
function clientCmdSetImageHealthHUD(%curHealth)
{
echo("healthImageHud has been called on the client");
// Skip if the hud is missing.
if (!isObject(HealthImageHUD))
{
echo("no HealthImageHud! Wrong!");
return;
}
// Ensure the HUD is set to visible while we have health / are alive
if (%curHealth)
{
HealthImageHUD.setVisible(true);
echo("HealthImageHud is visible");
}
else
{
HealthImageHUD.setVisible(false);
echo("HealthImageHud is hidden");
}
echo("current health is " @ %curHealth);
if(%curHealth > 75)
{
echo("health is good");
healthGood.setvisible(true);
healthOkay.setvisible(false);
healthCaution.setvisible(false);
healthDanger.setvisible(false);
}
if(%curHealth > 50 && %curhealth < 76)
{
echo("health is okay");
healthGood.setvisible(false);
healthOkay.setvisible(true);
healthCaution.setvisible(false);
healthDanger.setvisible(false);
}
if(%curHealth > 25 && %curhealth < 51)
{
echo("health is caution");
healthGood.setvisible(false);
healthOkay.setvisible(false);
healthCaution.setvisible(true);
healthDanger.setvisible(false);
}
if(%curHealth < 26)
{
echo("health is danger");
healthGood.setvisible(false);
healthOkay.setvisible(false);
healthCaution.setvisible(false);
healthDanger.setvisible(true);
}
}Save.And now, when the player's health changes in-game, the correct image should show.

About the author
One Bloke ... In His Bedroom ... Trying To Make Computer Games ... eventually ...
Recent Blogs
• Stylized Art Style is ... er ... Stylized, Plus Other Stuff• ChinaTown Ai Deathmatch Resource Plus Function Creep
• ChinaTown Multi AI DeathMatch With Recast Pathfinding Part 3
• ChinaTown Ai Deathmatch with Recast Pathfinding Part TWO
• ChinaTown Ai Deathmatch with Recast Pathfinding Part ONE
#2
These are exactly what people are looking for when they first come to a new engine. They have been explaining the basic concepts of how to start a game and they are well written.
Thumbs up. I have been learning a lot.
02/24/2011 (1:20 pm)
Steve thanks for all of the amazing tutorials that you have been posting lately. These are exactly what people are looking for when they first come to a new engine. They have been explaining the basic concepts of how to start a game and they are well written.
Thumbs up. I have been learning a lot.
#3
Sometimes numbers and bars simply arent the right communicator one need, we use this kind of approach as well in our game. It was the only way I could figure out to do the hitbox displaying in a proper and fast glance manner...
02/24/2011 (2:01 pm)
Nice to see this, and GJ.Sometimes numbers and bars simply arent the right communicator one need, we use this kind of approach as well in our game. It was the only way I could figure out to do the hitbox displaying in a proper and fast glance manner...
#4
02/24/2011 (5:02 pm)
Heck yeah dude! This is exactly what I was trying and failing to do back in December. Thanks!
#5
02/24/2011 (6:41 pm)
Nice color selections. May have to use this as reference for my silhouette health indicator... I pick colors and people are wtf? were you thinking :D
#6
To be honest I did it once and then rethought. More of a pain in the arse than I was expecting, it's more difficult to make things work in grey scale when you're not used to thinking about it.
Footnote:
Many moons ago when I was a whippersnapper (1990 I guess), I started out on an engineering course which was taught by an old bloke about to retire. He'd been in a foundry for most of his life, smelting "whatever" probably steel - used to be a lot of that in Yorkshire, anyhow, he used to look through a special window and withdraw the metal when it was a certain colour ... but new tests showed that he had been colour-blind the whole time. Turns out he didn't know either, doing everything in greyscale ... but in his time he had been repeatedly promoted because of his skills at being able to tell exactly when the metal was at the right temperature ... 256 greyscale FTW!
02/24/2011 (9:13 pm)
Of course I was thinking of our very own, "Silent Mike"!To be honest I did it once and then rethought. More of a pain in the arse than I was expecting, it's more difficult to make things work in grey scale when you're not used to thinking about it.
Footnote:
Many moons ago when I was a whippersnapper (1990 I guess), I started out on an engineering course which was taught by an old bloke about to retire. He'd been in a foundry for most of his life, smelting "whatever" probably steel - used to be a lot of that in Yorkshire, anyhow, he used to look through a special window and withdraw the metal when it was a certain colour ... but new tests showed that he had been colour-blind the whole time. Turns out he didn't know either, doing everything in greyscale ... but in his time he had been repeatedly promoted because of his skills at being able to tell exactly when the metal was at the right temperature ... 256 greyscale FTW!
#8
Enough color perceptually challenged people had complained to Turbine about certain puzzle wheel colors in DDO that they finally tweaked their color selection. Now I can go back and finish those quests! In lighted conditions I actually see colors - just not the right ones! My night vision however is better than an owls - 16k shades of gray :D
On a side not, and back on topic (sort of): back in the early planning for the FPS Example I had almost done something very much like this Resource, but the peeps in charge wanted numbers.
02/25/2011 (12:11 am)
Lol, nah, that don't need to be smaller.Enough color perceptually challenged people had complained to Turbine about certain puzzle wheel colors in DDO that they finally tweaked their color selection. Now I can go back and finish those quests! In lighted conditions I actually see colors - just not the right ones! My night vision however is better than an owls - 16k shades of gray :D
On a side not, and back on topic (sort of): back in the early planning for the FPS Example I had almost done something very much like this Resource, but the peeps in charge wanted numbers.
#9
I'm not colorblind (I'm an electrician - they test us before acceptance) but for us programmers it all comes down to numbers anyway. This episode of The Guild has a silly sequence where the guild leader is arguing about colors by their hex values.
02/25/2011 (7:35 am)
When in doubt about "safety" colors, you can always go to a government web site, the Occupational Safety and Health Administration for example, and look at the color guidelines.I'm not colorblind (I'm an electrician - they test us before acceptance) but for us programmers it all comes down to numbers anyway. This episode of The Guild has a silly sequence where the guild leader is arguing about colors by their hex values.
#10
I do have one suggestion though, to possibly make it a little more beneficial (code wise).
You could use a bitmap control and then set the bitmap as necessary (control.setBitmat(dangerImage.png);)
02/25/2011 (8:11 am)
very simple yet effective example, one who wanted to do a "CoD" approach could accomplish this by changing the borders to be red :)I do have one suggestion though, to possibly make it a little more beneficial (code wise).
You could use a bitmap control and then set the bitmap as necessary (control.setBitmat(dangerImage.png);)
#11
Yeah, that would reduce the amount of typing in the script above - in fact that's how I've been doing my "comicbook" cutscenes, using the same gui and changing the bitmap when the player clicks a "next" button. It's also how I change images on other parts of my HUD.
02/25/2011 (9:51 am)
@RobertYeah, that would reduce the amount of typing in the script above - in fact that's how I've been doing my "comicbook" cutscenes, using the same gui and changing the bitmap when the player clicks a "next" button. It's also how I change images on other parts of my HUD.
#12
02/28/2011 (12:21 pm)
Steve, awesome job on all the handy tutorials! Keep up the good work!
#13
03/02/2011 (6:18 pm)
wow that's awesome!!
#14
03/22/2011 (3:04 pm)
I love your tutorials.

Employee Richard Ranft
Vorpal Bunnies
I was going to suggest this approach but leave the code as an exercise for the reader. My kids hate me for this very reason.