Game Development Reference
In-Depth Information
The CreateHealthItem() function creates a new HUDItem for our player's health and adds it to the
HUD. (See Listing 6-40.)
Listing 6-40. Creating and Adding a Health Item to the HUD
void CreateHealthItem()
{
Texture HUDTexture = new Texture(m_Context, R.drawable.hud);
Shader Shader = new Shader(m_Context, R.raw.vsonelight, R.raw.fsonelightnodiffuse);
// ok
MeshEx Mesh = new MeshEx(8,0,3,5,Cube.CubeData, Cube.CubeDrawOrder);
// Create Material for this object
Material Material1 = new Material();
Material1.SetEmissive(1.0f, 1.0f, 1.0f);
Texture[] Tex = new Texture[1];
Tex[0] = HUDTexture;
BillBoard HUDHealthComposite = new BillBoard(m_Context, Mesh, Tex, Material1, Shader);
Vector3 Scale = new Vector3(1.0f,0.1f,0.01f);
HUDHealthComposite.m_Orientation.SetScale(Scale);
HUDHealthComposite.GetObjectPhysics().SetGravity(false);
// Set Black portion of HUD to transparent
HUDHealthComposite.GetMaterial().SetAlpha(1.0f);
HUDHealthComposite.SetBlend(true);
// Create Health HUD
Texture HealthTexture = new Texture(m_Context, R.drawable.health);
Vector3 ScreenPosition = new Vector3(0.8f, m_Camera.GetCameraViewportHeight()/2, 0.5f);
HUDItem HUDHealth = new HUDItem("health", m_Health,
ScreenPosition,m_CharacterSet,HealthTexture, HUDHealthComposite);
if (m_HUD.AddHUDItem(HUDHealth) == false)
{
Log.e("ADDHUDITEM" , "CANNOT ADD IN NEW HUD HEALTH ITEM");
}
}
The CreateHUD() function creates the HUD and the two items in the HUD, which are the player's
health and the player's score. (See Listing 6-41.)
 
Search WWH ::




Custom Search