Architecture

The HUD kit consists of the Flash UI assets and the C++ code that updates the HUD’s visual state. There is also a C++ simulation that provides an environment to drive the HUD with dummy data.

C++

The two main parts of the C++ code are the interface to the HUD view and the environment that provides data to the view. In the MVC paradigm, the interface would be the controller, the environment is the model and the Flash UI is the view. Files and classes that are prefixed with Fx define interfaces of the HUD Kit’s View core. Files without this prefix define interfaces for the demo or game simulation.

The adapter design pattern is implemented to decouple the simulation from the HUD View. The adapter translates requests between the simulation and the HUD View. To interface the HUD View with a new game, users need to develop a custom adapter class which interfaces with their game and the HUD View. This allows developers to reuse the HUD Kit conveniently without significantly modifying their game code.

The code detailed within this document presents an optimal implementation of Scaleform, leveraging the new Scaleform Direct Access API to accomplish UI updates and animations faster than ever before.

The C++ code consists of the following files (located in Apps\Kits\HUD and its subfolders).

Demo

HUD/Minimap View Core

Game Simulation

Flash

The Flash content for the HUD Kit is divided in two files: HUDKit.fla and Minimap.fla. These FLA files define and layout the HUD Kit’s UI elements for manipulation using Scaleform. They also include all images and icons displayed in the UI.

Both files are divided into several layers. Generally, each component or group of similar components has its own layer. Layers provide a convenient method for author-time control of element ordering based on depth. The top most layer will display on top of all other layers and so on.

In Scaleform, Flash animations can be handled using C++, ActionScript, or the Flash timeline. In this demo, the majority of HUD animations are handled on the Flash timeline via Classic Tweens. These animations are generally triggered by a GFx::Value::GotoAndPlay() call from C++.

HUDKit.fla

The HUDKit.fla file located in the Bin\Data\AS2 or AS3\Kits\HUD directory is the demo’s primary SWF. This file is loaded by the HUDKitDemo application at runtime. Every Flash UI element exists in this file except for the minimap view which is loaded by the HUDKit.fla at runtime.

Figure 2: HUDKit.fla layers

The HUDKitDemo registers the HUDKit MovieClip using an External Interface call on Frame 1 of the timeline:

ExternalInterface.call("registerHUDView", this);

This passes a pointer to the MovieClip which C++ can register with the C++ HUDView to manipulate the user interface.

Every layer, its MovieClips, layouts, animations, and Scaleform C++ managers will be discussed in detail in the HUD View section of this document.

Minimap.fla

Figure 3: Minimap Symbol

Minimap.fla includes the ‘Minimap’ symbol, the core of the Minimap. For the scope of this demo, the background is a static image and not an interactive 3D environment.

The player is denoted as a yellow arrow in the center, and heading is shown by the minimap border (North is marked). In addition to the player, the minimap view displays five icon types:

The capture points and powerups are sticky icons that stick to the view border when outside the view range but inside the detectable range. The Direct Access API method is used to provide the functionality to fade icons that enter and leave the detectable range. It is also used to attach and remove MovieClips from the Stage during runtime using C++.

This ‘Minimap’ symbol contains several layers. Layers provide a convenient method for author-time control of element ordering based on depth. The top most layer will display on top of all other layers and so on:

Figure 4: The layers of the 'minimap' symbol

The ‘Minimap’ symbol uses the com.scaleform.Minimap class (located under Bin\Data\AS2 or AS3\Kits\HUD\com\scaleform). This minimal class defines the path to the map image and the constructor of the minimap which registers the minimap with the HUDKitDemo application and loads the map image.