Game Development Reference
In-Depth Information
A slider's look can vary depending on the game style, but it usually will consist of a back-
ground, a cursor, a label to represent the minimum value, a label for the maximum value
and a label for the current value of the slider. The position of the labels is purely cosmetic
and entirely dependent on the look and feel of the game, the behavior of a slider is very
similar to another control we discussed previously, the scroll bar. This is a good example
of a place in which object oriented design allows us to reuse code and create new features
by extending class.
int& Minimum() { return m_minimum; }
int& Maximum() { return m_maximum; }
int Value() const { return m_minimum + (Ratio() * m_maximum); }
Inadditiontothescrollbar'sbehavior,wewillwanttoconstrainthevaluewithinsomelim-
its. The cursor of the scrollbar controls the value returned by Ratio(). The only remaining
thing would be to override the InternalDraw function to provide a custom look for a slider.
4.3.12 Menus
Menus are an important part of possibly every game that has ever been released. They
provide a way for players to select certain aspects of their gaming experience, they can be
as straightforward as choosing whether one or two (or more) players will play, or they can
be quite complex allowing players to modify core aspects of the game.
As a user interface programmer it is important to identify the parts that all menus have in
common and create a base class that handles the default behavior of any menu and also
provide the means to create new menus and change their behavior based on the require-
ments of the game's direction.
A menu consists of items, usually labels organized in some fashion that makes them easy
to select. Most menus use a top-down organization, in which the first option is used to
start playing and the next options can be used to configure the game's settings. Menus
must respond to different types of input, mouse input or touch input as well as keyboard or
gamepad navigation.
We will create a base class that will provide the shared functionality for all menus, in most
cases it should suffice, however it may happen that we want to specialize a given menu, in
this case we can do so by implementing different behaviors in each of the menu's virtual
interface.
Search WWH ::




Custom Search