Game Development Reference
In-Depth Information
Classified intel
In this section, we have used GUI.BeginGroup() to mask out the texture to show how
many hit points are left. The GUI.BeginGroup() function must be close to GUI.
EndGroup() .
In our code, we basically created the first group to contain the background texture, which is
the bar frame. Then, we drew another group on top of the first group, which contains the
bar texture as a clip mask. This second group's width will relate to the hit-point value left
for the player or enemy, as shown in the following code:
//Draw the background group
GUI.BeginGroup (Rect (110,15,156,21));
GUI.DrawTexture(Rect (0,0,156,21), frameTexture);
// Create a second Group which will be clipped
GUI.BeginGroup (Rect (0,0, player.GetHpPercent() * 156,
21));
GUI.DrawTexture (Rect (0,0,156,21), hpTexture);
//End both Groups
GUI.EndGroup ();
GUI.EndGroup ();
We can translate the preceding code into the following diagram:
Search WWH ::




Custom Search