Creating a HUD
From CryWiki
| ||||||||||||||
|
Contents |
Creating a HUD
Introduction
Setup
Getting started
Now that we’ve got the right files, we can start. Open start.fla, it should look like this:
This is just the layout of the HUD, imported from the design.psd file. The first thing we will do is converting a few textfields to Dynamic Text and embed the fonts. This is important, if you forget this step the text will be displayed as ’□□□□’ .
Double click the Health part on the lower left, this will get us in the Health movieclip. In there, select the 150. This textfield needs to be dynamic because we want to change the health in the code, obviously.
Change the type of the textfield to ‘Dynamic Text’ and name it health_txt. Also make the text unselectable by clicking on the highlighted button. Finally, click the ‘Embed..’ button and only select Numerals, since that’s the only thing we’ll need in this textfield.
Do the same for the other dynamic things (not the static text ‘HEALTH’, ‘AMMO’, ‘ENERGY’, ..): the energy value (energy_txt), the ammo (ammo_txt) and the suitmode (suitmode_txt) on top. Do note that when embedding fonts for the suitmode, we need more than just numbers, so select Uppercase, Lowercase, Numerals, Punctuation and Basic Latin.
As a side note, do NOT use formatting on your dynamic text fields, for example, Bold, Italic, doing so will prevent the font from embedding properly.
Now, select everything by pressing Ctrl+A and convert it to a symbol (Modify -> Convert to Symbol or F8). Name it ‘Root’ and select MovieClip as type. After that give it an instance name in the Properties panel: ‘Root’.
Next up, we will create a new layer called ‘ActionScript’. In there we will put in the code. Select the first frame on the ActionScript layer and in the Properties panel name it ‘restart’.
The last 2 steps are not –needed-, but the Crysis game dll always tries to go to the ‘restart’ frame of the ‘Root’ movieclip when the flash file gets loaded. If you do not do these last steps, everything should still work fine, there will just be an error in the console.
Press F9 with the ‘restart’ frame still selected, let’s get to the actionscript.
ActionScript
In the actionscript we will do the logic of our HUD. Since this is a simple example, we don’t have any animations. The only thing that’s dynamic is the changing of text.
Before we write the functions needed, I will explain how the flash file interacts with Crysis. The loading of flash files is handled in C++. When something needs updating, like the health/armor in our HUD, the C++ code will try and execute a flash function. With that we can update the HUD to the correct values. You can also send commands from flash to C++ with fscommand, but that’s out of the scope of this tutorial.
Now the question is, what functions are getting called for our HUD file? We know that we’re overwriting the HUD_AmmoHealthEnergySuit.gfx file, so let’s search for that in the c++ code (found in the sdk). There is 1 match:
|
| |
|---|---|
| |
So the next thing we will search for is ‘m_animPlayerStats’, since that is the object in where the flash file is loaded. We can see entries like
|
| |
|---|---|
| |
With Invoke C++ tries to execute a function in flash. We can clearly see what functions it’s trying to call: GaussHit, setMode, setEnergy, … . Also note that the arguments after the function name are parameters to the flash function, so we need to handle those aswell.
We have the information we need now, we know what functions are going to be called and we know what arguments there will be, so let’s start with the actual actionscript.
|
| |
|---|---|
| |
This is the setHealth function, which takes a single argument: the health value. If the arg is less than 0, we set it to 0 so we don’t get negative numbers. We then take the arg value and put it in the health_txt textfield, which is In the Health movieclip, and that is in the Root movieclip. Pretty simple. The rest of the functions are very similar:
|
| |
|---|---|
| |
The energy function is pretty much the same as the health one, and the suitmode function takes a String as argument. We also make the text uppercase.
Finally, we also want the ammo value in lower right. If we look in the C++ code we can see it takes more than 1 argument:
|
| |
|---|---|
| |
It takes 7 arguments, we can see the function is also passing on grenade info, but we only want the ammo value.
|
| |
|---|---|
| |
We are only using the second argument, the ammo value, and put it in the ammo_txt textfield.
That’s all that’s needed in the flashfile. Now we want to save our flash file and export it to .swf (File->Export->Export Movie) and name it ‘HUD_AmmoHealthEnergySuit.swf’.
Setting up the MOD
Time to set up our modfolder to test the HUD. Place the .swf file we just exported in Crysis/Mods/MyMod/Game/Libs/UI (Create folders as necessairy). We will also need to rename the file to HUD_AmmoHealthEnergySuit.gfx. This is because Crysis will try to load that file and not the .swf one.
We can try and test the mod now: Launch the Editor or Crysis with –MOD MyMod.

