Game Development Reference
In-Depth Information
17.4 Overlays
A very common way of presenting information to the player is by using overlays .
Overlays are basically images that can be displayed on top of the game world to
present information or to provide a user interface such as a menu, a mini map, status
information and more.
Overlays can present an entirely new game state (such as a 'game over' overlay),
but they can also supplement the game world by only providing information to the
player. For example, many strategy games provide information about the number of
units selected, the available resources, ongoing building processes, items gathered,
and so on. These kinds of overlays are generally always present on the screen, and
together they are called the Heads-Up Display or: HUD.
Jewel Jam has a very basic HUD. It consists of a frame where the score is dis-
played, and it has a help button that can be pressed to view a frame with help infor-
mation.
Next to the HUD, we want to show a 'game over' overlay when the jewel cart
moves out of the screen. We add this overlay to the game world as well, and set its
visibility to false :
gameover = new SpriteGameObject("spr_gameover", 100, "gameover");
gameover.Visible = false ;
gameover.Position = JewelJam.Screen/2
gameover.Center;
this .Add(gameover);
Also, we add a property to the JewelJamGameWorld class to check if the jewel cart is
outside of the screen:
public bool GameOver
{
get
{
JewelCart jewelCart = Find("jewelcart") as JewelCart;
return (jewelCart.Position.X > JewelJam.Screen.X);
}
}
We can then use that property in the HandleInput method, so that the player can press
the space bar to restart the game, as follows:
if ( this .GameOver)
{
if (inputHelper.KeyPressed(Keys.Space))
this .Reset();
}
We override the Reset method because we need to do a little extra work when the
game restarts. Notably, we have set the visibility of some of the overlays to false so
Search WWH ::




Custom Search