Tip:
Highlight text to annotate it
X
Hey, hey everybrody! This is Matthew Doyle again from Scaleform.
I'm bringing you part 4 of the UDK HUD tutorial series.
Now, as you recall, in part 3 we talked about GFxMinimapHud.uc, and we left off with UpdateGameHud().
Well, I'm gonna pick up right there where we left off.
So, without further ado, let's go ahead and get started.
UpdateGameHUD() updates the HUD’s record of which player has the highest score...
in a Free for All game.
This information is not always displayed in the HUD since it depends on the gametype.
Now, the only truly GFx related code here is on line 417,
where we set the enemy name textfield to display the name of the highest scoring player.
Now this brings us to probably our most critical function - TickHud().
If you remember, TickHud() is called by UTGFxHudWrapper after every game frame is rendered.
It is this function that does all the HUD element updates.
We start off declaring a whole lot of local variables.
Most of these variables will be used to store game data,
such as vehicles, weapons in use, and player replication.
We also set up ASDisplayInfo and ASColorTransform objects that we’ll later apply to MovieClips in the scene.
ASDisplayInfo will be used to scale graphical bars on the HUD, just as it was used in the Init function above.
ASColorTransform will be used to change the color of various HUD elements...
using the ASColorTransform data structure of GFxObject.
We start out by caching references to UTGameReplicationInfo for the game,
and UTPlayerReplicationInfo for the local player.
If these values are valid, we set the game time displayed on the HUD at _root.teamStats.roundTime...
to either the remaining time or the elapsed time depending on whether there’s a time limit or not.
We also call UpdateGameHud() here.
Next up, we determine wether the player is on foot, in a vehicle, or in a mounted weapon.
And we store that information in UTP and UTV.
Take note that if the player is neither on foot or in a vehicle of some kind,
then we run ClearStats() to reset all data to the new game state,
and we exit the TickHud() function with a return statement.
On line 482, we update the minimap, passing it the current zoom level.
In the interest of time, I'm only going to cover two of the player stat UI updates -
Vehicle and Health.
Starting with vehicles, we test to see if the player’s state of travel (foot or vehicle)...
has changed since the last update.
Since there is a different PlayerStat’s frame for vehicles, we use gotoAndPlay()...
to switch between frames 2 (player on foot) and 3 (player in a vehicle)...
the first time a change is found.
We do this because we only want to update the various UI elements when a change has actually occurred.
Finally, we set LastVehicle to be the current vehicle (if any).
And we set the other stats to the initialized values.
The next block tests to see if the player's health has changed...
by comparing the current health at UTP.Health with the last known player health.
If there was a change, then we first update the heatlh text field using SetText,
and passing the value stored at UTP.Health.
We then determine the correct XScale value for the health bar with some basic math.
Now, if DI's XScale is greater than or equal to 100%, we basically set it to the max size.
After that we determine the color change we want based on a little math,
using Multiply and Add on the R, G, B values of the Cxform data structure.
Using Cxform, we then set the color of the bar with SetColorTransform().
And using DI, we also set the bar's XScale with SetDisplayInfo().
Last of all, LastHealth is set to the current player health.
Ok, let's move on to the next function.
I'm going to skip to DisplayHit(), actually.
If you recall from the previous video, DisplayHit() is used to show the hit direction indicator movie clips...
on the HUD when the player is being shot.
It accepts the direction as a vector,
the amount of damage,
and the damage type as parameters.
I'm not going to go into detail for most of this function, but essentially it does a bunch of math...
to determine where the player was shot from.
On the last line, it then takes that information and uses it to determine...
which of the 8 movie clips stored in the HitLocMC array to display by using GotoAndPlay().
It tells that movie clip to goto and play the "on" keyframe.
Go into Flash and drill down into the dirHit movie clip on stage.
Inside you'll find 8 layers - one for each direction.
If you double click on any one to enter its timeline,
you'll see that it has a keyframe labeled "on" as expected.
The next few functions are fairly self explanatory,
and follow the same procedures we've already discussed, so I'm gonna go ahead and skip those.
That leaves us with the last function, AddDeathMessage().
Like AddMessage() above, it is called from the LocalizedMessage() of UTGFxHudWrapper.
It expects three parameters - the player doing the killing, the player killed,
and the type of damage that killed the player.
First, it gets the name of the killer and sets the string msg to that name.
It then gets the index number of the weapon that causes the type of damage received as a parameter.
Using the index value, it then creates an html image tag specifying either...
one of the weapon icons or the skull icon as the source image, and appends that tag to the death message.
If you look in the library panel of the udk_hud Flash file, you'll find these icons...
in the log assets folder and the weapon assets folder.
Next, it gets the dead player's name and appends it to the death message.
The last thing the function does is to send the entire html text string stored in msg,
or message, to the AddMessage() function.
And, AddMessage() displays the new death message on the HUD message log.
Alright this brings us to the default properties.
And the default properties are fairly self explanatory.
The most crucial line here tells the class which SWF file to use with MovieInfo.
In this case, we want to use the udk_hud SWF file found in th UDKHud package.
Alright guy and gals!
We made it through without hurting ourselves too much.
I hope no one got an eye put out or anything like that.
I know this is a lot to digest, but I hope this tutorial helps you get a better grasp on the HUD.
We'll cover the minimap in the next video, so stay tuned for that one.
Until then, as always, I am your narrator,
Matthew Doyle for Scaleform, signing off!