Translating the design

The design sketch of Battlecry's user interface design should be able to display some simple assets for displaying the player's current health, the score of the game, a joystick, and an action button.

Translating the design

We covered the joystick and action button in the Input chapter so we can focus on the health display and showing the score. We need a nice font for displaying text and some images to show the health. In addition, we will want to build a main menu for the game that will consist of a button to start the game and one that will show the credits.

Immediate mode game user interfaces

The Unity game engine provides developers with a complete integrated system for game user interface (GUI) development. These GUIs are built using an immediate mode approach to defining the GUI and responding to its events. For most games this will not be an issue and will be one of the easiest ways for you to put a HUD and simple controls on the screen. However, as it is an immediate mode API, the developer is very close to the mechanics of how the UI operates.

As an example, we can look at how to construct a simple GUI that displays a button on the screen. As you might have guessed, since there are no tools, and as we're in immediate mode, we have to manually specify the layout for the components on the screen.

function OnGUI () {
   if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
      print ("You clicked the button!");
   }
}

Despite how different this may feel from hopping into Flash, Photoshop, Objective-C, or your favorite GUI framework, immediate mode GUIs are nothing new. In a traditional GUI framework, you setup your GUI components in a variety of classes and then setup callbacks and messaging systems so that the event loop can relay data from the components to the actual application logic that will handle the events. So what's wrong with this, you may ask. At the end of the day you will find that you have code all over your application – especially if you're really trying to be object-oriented and are designing your application for reuse.

While this is something that makes sense for a complex business application that may have to change its layout dynamically based on user-type, screen resolution, or the data being used, that is not the problem that we're trying to solve with our game. You will find that an immediate mode GUI is very compact, with all of the logic that makes your game work generally in a small number of places. Any state data necessary for the UI is made available to all of the interface components without the need for querying or passing data. This makes the application easier to follow and is very performance friendly.

..................Content has been hidden....................

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