Game Development Reference
Our current health is displayed on the top-right corner of our health bar. Let's take
a look at how it changes as our health decreases as well:
As you can see, the integer in the corner certainly makes it a bit easier to quickly
digest exactly how much health is remaining. In the next two recipes we'll cover
how to do this with our ammo!
How it works...
Not much is going on here. We add a few necessary variables to our DrawHealthText()
function to allow the text to be displayed. From there we're calling various Canvas
functions to perform activities such as drawing the actual text, coloring, positioning
on screen, and sizing.
We do add a new function to the mix here, however, with the addition of HudOffset() .
The purpose of this is to align our text in the same corner as our health bar, and then
offset it by a given value which we declare in our DefaultProperties block.
Displaying a bar for the player's ammo
Visualizing our player's health is essential, but their ammunition count is nearly just as
important. Games in recent memory have taken alternative approaches to illustrate this kind
of information, including the Halo series, which displays the current ammo count on the end
of the rifle.
We could mimic this with Scaleform, but again, that's a discussion for another day. We're
going to keep things simple again, as we aren't using Scaleform. So let's get started with
displaying our ammo bar!