Windows Phone 7 Sensors and XNA
Pinch Zoom Touch Panel: XNA Pinch Zoom Demo
Back to main page

Release 1.0 (XNA V4.0)
9/15/2010


1. Topics Covered

This program demonstrates XNA programming with the Touch panel. You may wish to download the source code, open the project and refer to the source code while follow the discussion. Topics covered in this tutorial includes:

2. Demo Program Behavior

You will see a screen similar to the following when you compile the attached source code, dispatch to WP7 device/emulator, and run the program.
Pinch Zoom Image
There are three objects on the screen: the BasketBall, Vase, and Background image. You can:

The next section describes the details of the implementation.


3. Solution Structure and External Resources

With the source code open, open the SolutionExplorer (if not already opened, under ViewSolutionExplorer) in the IDE. Examine the SolutionExplorer and notice:
Solution Explorer Image

4. Implementation Details

With the simple solutuion structure, we can focus our attention on the source code file: PunchZoomDemo.cs.

4a. Main Source Code File Structure (PinchZoomDemo.cs): The  following figure shows the structure of the program:

Code Structure Image
Notice that: Notice that none of the instance variables are defined to support the actual touch panel operation. Touch panel support is well integrated into XNA API, just like the GamePad, or the Keyboard.  Just like the GamePad and Keyboard, to understand how to work with the TouchPanel, we can focus on the Initialize() and the Update() functions.

The Initialize() Function:

Code Structure Image
The above listing shows the initialization and activation of gesture supported by the TouchPanel, where we registers all interested gestures with the bitwise OR "|" operator.
The Update() Function:

Code Structure Image
The above listing of the Update() function shows that, as in working with the GamePad, we have to (the following are expanded views of the Labels in the above Update() function):
Notice that the selection/dragging and zooming operates with reference to the initial touch position. Please refer to the discussion in SimpleLibrary documentation on the details of selection and zooming.

5. Self Test And Exercises


References


Kelvin Sung
Computing and Software Systems
University of Washington, Bothell
ksung@u.washington.edu
Project home page: The Game-Themed Introductory Programming Project.

Microsoft Logo This work is supported in part by Microsoft Research under the Computer Gaming Curriculum in Computer Science RFP, Award Number 15871 and 16531, and Microsoft Higher Education.
9/15/2010