Game Development Reference
In-Depth Information
Listing 6-41. Creating the HUD
void CreateHUD()
{
// Create HUD
m_HUD = new HUD(m_Context);
// Create Score HUD
Vector3 ScreenPosition = new Vector3(-m_Camera.GetCameraViewportWidth()/2 + 0.3f,
m_Camera.GetCameraViewportHeight()/2, 0.5f);
// Create Score Item for HUD
HUDItem HUDScore = new HUDItem("score", 0, ScreenPosition,m_CharacterSet,null,m_HUDComposite);
if (m_HUD.AddHUDItem(HUDScore) == false)
{
Log.e("ADDHUDITEM" , "CANNOT ADD IN NEW HUD ITEM");
}
CreateHealthItem();
}
The UpdateHUD() function updates the numerical values of the player's health and the player's score
in the HUD. (See Listing 6-42.)
Listing 6-42. Updating the HUD
void UpdateHUD()
{
m_HUD.UpdateHUDItemNumericalValue("health", m_Health);
m_HUD.UpdateHUDItemNumericalValue("score",m_Score);
}
The onSurfaceCreated() function requires some modifications to initialize our HUD. First, the viewing
height and width on the actual Android device is retrieved. The camera is then modified with these
values. Next, the character set that will be used with the HUD is initialized. Finally, the HUD is
created. (See Listing 6-43.)
Listing 6-43. Modifying the onSurfaceCreated() Function
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config)
{
m_PointLight = new PointLight(m_Context);
SetupLights();
// Create a 3d Cube
CreateCube(m_Context);
// Create a Second Cube
CreateCube2(m_Context);
// Create a new gravity grid
CreateGrid(m_Context);
 
Search WWH ::




Custom Search