Game Development Reference
In-Depth Information
How it works...
The process is done in the same manner as our health bar. We start off by adding a function
to draw our ammo bar. Really though, UDK calls this a tile with its DrawTile() function, but
we prefer to call it a bar.
Our ammo bar needs a specific value to be drawn, however, to represent both the maximum
and current ammo. We define and then use those in the DrawAmmoText() function, and
use those parameters in the DrawAmmoBar() function.
The bar itself is drawn in the top-right corner of the screen, as defined by
CorrectedHudPos() . It's a lot thrown at you at once, so bear with me. In
DrawAmmoText() , we define our position on screen with the Vector2D variable POS .
POS is actually set to our CorrectedHudPos() function which is a function that takes
AmmoPosition as a Vector2D parameter and uses that information to determine where
the ammo will be drawn on screen.
Drawing text for the player's ammo
We've got a bar to illustrate our current ammo count against our maximum capacity, but it's
always useful to see exact values. Therefore we're going to add text for both of these values,
similar to how we did it for our health.
Getting ready
Open your IDE and have your TutorialHUD class ready to be altered.
How to do it...
This is going to be very similar to the steps we took in the recipe for displaying an integer to
represent our pawn's health. The only major change we need to make here is to the properties
that we'll be accessing and using. Rather than displaying our pawn's health, we'll be using the
ammo property for our pawn's currently equipped weapon.
Let's start by adding the only variable we'll need for this one. It stores the offset we
apply to the text from our ammo bar.
/** Positioning for Ammo bar and text */
var vector2d AmmoTextOffset;
In our DrawAmmoText() function, let's add our new local variables and Canvas
functions to draw the text.
* Draws the ammo text and bar
Search Nedrilad ::

Custom Search