Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building your First Mobile Game using XNA 4.0

You're reading from   Building your First Mobile Game using XNA 4.0 A fast-paced, hands-on guide to building a 3D game for the Windows Phone 7 platform using XNA 4.0

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849687744
Length 158 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Thomas Goussaert Thomas Goussaert
Author Profile Icon Thomas Goussaert
Thomas Goussaert
Brecht Kets Brecht Kets
Author Profile Icon Brecht Kets
Brecht Kets
Arrow right icon
View More author details
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image