Using touch
As Windows Phone devices have a touch screen, XNA Game Studio also offers support for (multi-)touch. This is fairly straight forward and all managed by the static TouchPanel
class. Good practice when starting your game is to check the capabilities of the device, like the maximum touch count. That way we can be sure that the device meets our expectations. We can do this by using the static GetCapabilities
method.
TouchPanelCapabilities tc = TouchPanel.GetCapabilities(); if (tc.IsConnected) { return tc.MaximumTouchCount; }
Looping over all touch locations is also very straight forward. The static class TouchPanel
has a GetState
method that returns a TouchCollection
. This collection contains TouchLocations
. We can use those to get the positions we need. Note that we should only call the GetState
method once per frame; otherwise calling the GetState
method twice will return refreshed data, resulting in missed events.
TouchCollection touchCollection = TouchPanel.GetState(); foreach...