Game Development Reference
In-Depth Information
when the external code (in this case, the Game class) detects a click or tap. The
ProcessClick() method without parameters exists to allow for gamepad interac-
tion with the controls by clicking on the currently focused control instead of trying to
detect the control based on the mouse position.
This brings us to the focus methods. These allow the menu to track the currently
focused control, and also cycle through all of the controls that can be focused on
(because you don't want to focus on the information text).
This menu is a bare bones implementation for this example; however, there are
many different ways to handle user interfaces in games. With Windows 8 you can
even choose to use XAML for your interface, and render over your game. If you
haven't encountered it before, XAML stands for Extensible Application Markup
Language , and refers to the XML-like language that can be used to define the look
of a user interface. Although outside of the scope of this topic, this system can be
used with your DirectX game to handle the user interface (it uses DirectX to render it-
self) and, using C++/CX or the WinRT component system mentioned previously, you
can connect the two together to create a complete system. If you find that you need
more than the basic UI functionality outlined here, you may want to consider using
XAML to handle it for you.
The implementation for the Menu class is as shown in the following code snippet:
void Menu::Draw(std::shared_ptr<SpriteBatch>
spriteBatch)
{
for (auto c : _controls)
{
if (c->GetVisibility())
c->Draw(spriteBatch, c == _focusControl);
}
}
The Draw() method simply draws the controls by iterating through the list and call-
ing the control's Draw() method if it is visible, as can be seen in the code snippet
that follows:
Search WWH ::




Custom Search