Game Development Reference
In-Depth Information
Chapter 20
Menus and Settings
20.1 Introduction
In the Jewel Jam game, we have already seen a few basic examples of adding GUI
elements to your game such as a button or a frame. In this chapter, we are going to
add a few more GUI elements, such as an on/off button and a slider button. Secondly,
we will show how you can read and store game settings, such as music volume or
whether hints are allowed or not.
20.2 Setting up the Menu
As an example, we will show how to define a basic 'options' menu containing two
controls: one for switching hints on or off, and one for controlling the volume of the
music. First, we need to draw the elements surrounding these controls. We first add
a background to the menu. Second, we add a text label to the menu to describe the
'hints' control. We are going to use the TextGameObject class taken from the Jewel
Jam game for that. We define the text that should be drawn, and we place it at the
appropriate position:
TextGameObject onofftext = new TextGameObject("Fonts/MenuFont", 1);
onofftext.Text = "Hints";
onofftext.Position = new Vector2(150, 340);
onofftext.Color = Color.DarkBlue;
gameWorld.Add(onofftext);
Similarly, we add a text label for the music volume controller. For the complete
code, see the PenguinPairs2 example belonging to this chapter.
 
Search WWH ::




Custom Search