Game Development Reference
In-Depth Information
Pointers
Touch screens are defining the current generation of devices, and to make supporting
these devices easier we have a new API that combines touch, mouse, and pen input
into the Pointer API. This API abstracts the type of the device away so that you can
focus on the common aspect between the three different devices, the actual pointer.
Unless you need built-in gestures, using the Pointer API is your best option to cover
both the mouse and touch screen in one go.
The pointer events provided by Windows are exposed through the CoreWindow ob-
ject that we have in our GameApplication class (this inherits from the IFrame-
workView ); you'll see two of them there already: OnPointerPressed and
OnPointerMoved . Let's add one more to support all of the main interactions you can
have using a pointer device: OnPointerReleased .
Add the following private prototype to the GameApplication.h :
void
OnPointerReleased(Windows::UI::Core::CoreWindow^
sender, Windows::UI::Core::PointerEventArgs^
args);
Now we need to connect this method up to the window event, which we will do in the
SetWindow() method in the GameApplication class. The following code sets a
new TypedEventHandler for pointer events, which will bind our new method to the
correct event. We can bind the other two pointer events in the same way. Don't forget
to implement the prototype that we've defined earlier, before continuing.
window->PointerReleased +=
ref new TypedEventHandler<CoreWindow^,
PointerEventArgs^>(this,
&GameApplication::OnPointerReleased);
In this code we want to use the pointer to let us move the player ship back and forth
across the screen, by pressing the side of the screen that we want to move towards.
Search WWH ::




Custom Search