Replacing the HUD

The HUD is provisioned in the file MyGame.UC and the example HUD Epic Games includes is 'UTGame.UTHUD', which has a dynamic compass, a health bar, and an ammo count, and a crosshair for aiming. These can be either modified or completely replaced, and there are various ways to make a working HUD, so what we will do here is just assume you want to remove the existing HUD and are comfortable adding your own content once you know what goes where. Most HUDs are now built upon Scaleform, and to get started with that, in respect of UI, it could be a good idea to look at http://udn.epicgames.com/Three/ScaleformWorkflow.html. An example of how the HUD and camera relate is at http://forums.epicgames.com/showthread.php?t=721726. Chapter 10, The Way of the Flash UI also discusses the basics of working with Scaleform.

In this section we are not going to cover comprehensive HUD provisioning, only some simple configuration tricks that are handy, that will expose users to the bare bones of this extensive body of content.

Tip

The new default map types begin with no GameType and therefore no HUD. Others begin with UTGame (which was the default up till the July 2011 version and can still be set in View | WorldProperties | Game Type). In any scene it is worthwhile to know that to show no HUD at all we can use the Toggle HUD action or Toggle Cinematic Mode action in Kismet with Hide HUD ticked in its properties.

Using UTGame, you may not only want to hide not just the HUD but the Unreal Tournament legacy weapon from the view too. After all, there's no point seeing a laser rifle bobbing in front of you when your game is a caveman simulator for instance. Neither of the HUD toggles will hide the UTGame weapon, but in this case you can also add a Player Spawned event in Kismet (not a Level Loaded since the player must spawn first) and connect to it a New Action | Pawn | Give Inventory action. Set the Give Inventory action so it has a new entry [ Replacing the HUD ] with None set and tick on the property Clear Existing.

How to do it...

  1. An original HUD design really sets the tone of any game. If you want to start your own MyHUD class, particularly now that Scaleform has been added to UDK, you can try:
    class MyGame extends UDKGame
        config(MyGame);
    
    DefaultProperties
    {
      HUDType=class'MyGame.MyHUD'
    //  bUseClassicHUD=true 
    // This code sample cannot use the line above as it does not extend from UTGame but from UDKGame...
    
    }
  2. The highlighted line tells UDK to use the classic HUD type to avoid an error if your game extends UTGame.UC.
  3. You can then continue to provision your MyHUD.UC with at least:
    class MyHUD extends UDKHUD;
    event PostRender()
    {
    DrawGameHud
    }
    
    //PostRender occurs after all the content of the game is sorted out.
    function DrawGameHud(){
     if ( !PlayerOwner.IsDead() && !PlayerOwner.IsInState('Spectating'))
    {
    
    // Set the position on the screen...
    Canvas.SetPos(Canvas.ClipX/2,Canvas.ClipY/2);
    
    // Set the text colour to white...
    Canvas.SetDrawColor( 255, 255, 255, 255 );
    
    // Sets a medium font to use...
    Canvas.Font = class 'Engine'.static.GetMediumFont();
    
    ///You can also use GetSmallFont or GetHugeFont
    
    // Sets the text to display...
    Canvas.DrawText( "This HUD is basic!" );
    }
    }DefaultProperties{
    }
  4. Comment out the DrawText instruction if you don't want it there. Instead, use Draw Text actions in Kismet. This example is just a starter. If you want to adjust text colour, remember that the 255,255,255,255 first three numbers are RGB values and the fourth is Alpha, for transparency.
  5. Not everyone wants to write an entire HUD replacement, so if all you want to do is remove the rather large compass from the default HUD, you can go to line 481 of the file: C:UDK~DevelopmentSrcUTGameClassesGFxMinimapHud.UC and then comment out: //Minimap.Update(CurZoomf);

    By default the hotkeys F2 (map) and F3 (minimap) are for in game map toggling.

    If you like the minimap but want to make it smaller, leave the previous line as it was, and instead press Ctrl + F and search for 85; which happens to be the scale value for the compass and should expose the lines:

    Minimap.SetFloat("_xscale", 85);
    Minimap.SetFloat("_yscale", 85);
    
  6. Comment those out with //, so you don't have to remember the defaults, then add in this replacement underneath:
    Minimap.SetFloat("_xscale", 25);
    Minimap.SetFloat("_yscale", 25);
  7. If all you want to do is remove the targeting crosshairs, open C:UDK~DevelopmentSrcUTGameClassesGFxMinimapHud.UC and in the DefaultProperties put in false instead of true in the line: bDrawWeaponCrosshairs=true.
  8. Since there is a function ToggleCrosshair(bool bToggle) you can always add a hotkey to the DefaultInput.INI file, as we discussed in earlier recipes, such as: Binding a keyboard shortcut to a player action.
    How to do it...
  9. Another inroad into adjusting the HUD is to learn how the art assets are assigned for it, by looking in the editor in the Content Browser, under UDKGame | GFx | UDKHUD where you can access, change and replace the art or perhaps just find the name of the asset (right-click on it and choose Copy Full Name to Clipboard) so you can then locate it in the appropriate HUD class and swap it for the asset you want to use.
  10. An example would be, again using the compass, to Create a Copy of ut3_minimap_compass which is in the package UDKHUD and place it into a Backup._ut3_minimap_compass. Here, Backup is a new package name and the prefixed underscore is to adjust the name, so we avoid a conflict while keeping it easy to remember in case this gets reversed later on.
  11. Now search for the provided Packt.Texture.AltCompass, which is a 512x512 TGA with an embedded alpha channel, and looks square.
    How to do it...
  12. Right-click on this and choose Create a Copy and then set the info to UDKHUD.ut3_minimap_compass (the one we replaced out before).
  13. If for some reason you have troubles juggling files, the original asset is found in: C:UDK~UDKGameFlashUDKHudUDK_minimaput3_minimap_compass.PNG.
  14. Now PIE to see if a square compass shows instead of the round one, supposing you haven't already removed the compass as in step 2. Bear in mind that if you do an update to the UDK content this may be refreshed by the updater.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.171.246