Game Development Reference
In-Depth Information
2.
We need a function to draw the player's name on the screen.
/**********************************************************
* Draws the text for the pawn's name
**********************************************************/
function DrawPawnNameText()
{
local Vector2D TextSize, POS;
local String PlayerName;
/** Sets the player name */
PlayerName =
PlayerOwner.PlayerReplicationInfo.PlayerName;
/** Sets the name position */
POS = CorrectedHudPOS
(NamePosition,NameCoords.UL,NameCoords.VL);
/** Draws the text */
Canvas.Font = TutFont;
Canvas.SetDrawColorStruct(WhiteColor);
Canvas.SetPos(0.9f *(Canvas.ClipX/2), POS.Y);
Canvas.DrawText
(PlayerName,,TextScale / RatioX,TextScale / RatioY);
Canvas.TextSize(PlayerName, TextSize.X, TextSize.Y);
}
We have a Vector2D variable to store the size of our text as well as the position
on screen. Moreover, we have a string to store our player's name.
Our name is grabbed from our PlayerController class, in our case
PlayerOwner . If you look into HUD.uc , which is what our TutorialHUD
class extends from, you'll see that PlayerOwner is a player controller, and
defined as the player controller that this HUD belongs to.
We cut the screen in half with the call to Canvas.SetPos() , which places our
text in the middle of the screen. The problem, however, is that it centers the origin
of the text, which is the top-left corner. Because of this we need to offset it slightly.
Therefore, we use the float 0.9 to compensate for this difference, as seen by the
line Canvas.SetPos(0.9f *(Canvas.ClipX/2), POS.Y); .
3.
Of course, we don't want to forget to have DrawHud() call our function either.
It should now look like this:
/**********************************************************
* Draws the HUD
**********************************************************/
function DrawHUD()
 
Search Nedrilad ::




Custom Search