Game Development Reference
In-Depth Information
public void Update(double elapsedTime) { }
public void Render()
{
Gl.glClearColor(1, 1, 1, 0);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
_renderer.DrawText(_title);
_renderer.Render();
}
}
The StartMenuState uses the font passed into the constructor to make the
title text. The text is colored black, and then it's centered horizontally. The ren-
der loop clears the screen to white and draws the text. To run the state it needs to
be added to the state system and set as the default state.
private void InitializeGameState()
{
// Game states are loaded here
_system.AddState("start_menu", new StartMenuState(_titleFont));
_system.ChangeState("start_menu");
}
Run the program and you should see something similar to Figure 10.4.
This stage is just a first pass. The title page can be refined and made prettier later.
At the moment, functionality is the most important thing. To finish the title
screen, the start and exit options are needed. These will be buttons, which means
a button class will need to be made.
The buttons will be presented in a vertical list. At all times one of the buttons will
be the selected button. If the user presses Enter on the keyboard or the A button
on the gamepad, then the currently selected button will be pressed.
A button needs to know when it's selected; this is also known as having focus.
Buttons also need to know what to do when they've been pressed; this is a great
place to use a delegate. A button can be passed a delegate in the constructor and
call that when it's pressed, executing any code we want. The button will also need
methods to set its position. These requirements for the button describe some-
thing like the following class. The Button class is reusable so it can be added to
the Engine project so it may be used in future projects.
 
Search WWH ::




Custom Search