Game Development Reference
In-Depth Information
spButton->SetClickHandler(
[this] (TextBlock *s)
{
StartGame(Mode_Singleplayer);
});
Here we're setting the click handler for the Singleplayer button, and inside that
we're using something called a lambda, which is a new language feature that effect-
ively allows us to define a function within another function, and use it as an object.
There are three parts to the lambda here. The first part, [this] is the capture sec-
tion. Here you can specify objects (pointers or references) within the containing func-
tion's scope that will be made available to the lambda. We provide the [this] point-
er so that we can call the StartGame() method from within the lambda. (TextB-
lock *s) represents the parameter block for the lambda function, and in this case
we need to match the method signature that the SetClickHandler() method ex-
pects, which is just a TextBlock parameter. Finally, we have the function body in-
side the opening and closing braces.
Think about what you might need to do to integrate menus with the sample game, or
what other classes you could add. Remember that the less you write the better, and
if a text block handles your needs for input, you don't necessarily need a button, as
shown earlier. If you wanted a texture for a button, how might you go about adding
support for that using what you have learned in this topic?
Now let's move on to the real focus of this chapter: networking, and how you can use
features and APIs in Windows 8 to add support for this feature.
Search WWH ::




Custom Search