Game Development Reference
In-Depth Information
How it works...
This is almost identical to our DrawHealthText() function. We add one variable to our
DrawAmmoText() function to allow the text to be displayed. From there we're calling various
Canvas functions to perform activities such as drawing the text, coloring, positioning on
screen, and sizing.
Again, we use HudOffset() to align our text in the same corner as our ammo bar, and then
offset it by a given value which we declare in our defaultproperties block.
Drawing the player's name on screen
When I think of drawing the player's name on screen the Doom guy always comes to my
mind. The image of his mug shot centered on the bottom of my screen is perhaps burned
into my mind forever. With that in mind, I thought it would be nice to display our pawn's name
on screen in the same manner. Of course, we could always replace the pawn's name with
something like an image of its face just as easily.
Sometimes it's nice to know exactly which player you are controlling, especially in a multiplayer
game. Often you'll just want to know if you are LocalPlayer01 or LocalPlayer02. You could, of
course, have a user input their name before a game starts and then grab that data and draw
it on screen as well. Let's discover exactly how to draw this on screen.
Getting ready
Open your IDE and have your TutorialHUD class ready to be altered.
Things are going to be pretty simple in this chapter, as we've done most of this work in our
previous recipes.
How to do it...
Drawing a player's name on screen isn't much different from drawing an integer to represent
the pawn's health or ammo count. We're going to store texture coordinates for our name, along
with a position in 2D space for where it will be displayed on screen. From there we grab the local
player controller's name and draw it on screen using the coordinates we stored earlier.
1.
Just as we did before, let's begin by adding the variables for our new text.
/** Position the name text */
var Vector2D NamePosition;
var TextureCoordinates
NameCoords;
 
Search Nedrilad ::




Custom Search