For Windows Phone7, there are three main ways to interact with users: gestures, buttons, touch and some sensor signals (such as gravity sensing). For the last one, learn Windows Phone7 development together (14th. device), so the interaction methods used by XNA games are the same. But for XNA, Windows phone7 and Windows are quite different. Its main functions are Microsoft. Xna. Framework. Input and Microsoft. Xna. Framework. Input. TouchPanel.
I. Keys: for keys, only the Back key is controllable. The other two keys are not controlled.
Public void Update ()
{
If (GamePad. GetState (PlayerIndex. One). Buttons. Back = ButtonState. Pressed) // This is added by the system.
{
//...
}
}
2. Touch: The status is also very small, only Move, Press, Release.
TouchCollection touchState = TouchPanel. GetState ();
Foreach (TouchLocation location in touchState)
{
Switch (location. State)
{
Case TouchLocationState. Pressed:
Break;
Case TouchLocationState. Moved:
Break;
Case TouchLocationState. Released:
Break;
}
}
3. gesture: different applications can be triggered by different actions on the screen by hand. The touch is very similar, but it is much more than its status and needs to be specified.
TouchPanel. EnabledGestures = GestureType. FreeDrag; // This parameter must be set before a gesture is specified. Otherwise, an error is reported.
If (TouchPanel. EnabledGestures! = GestureType. None)
{
Switch (TouchPanel. ReadGesture ())
{
Case GestureType. Tap:
Break;
Case GestureType. DoubleTap:
Break;
Case GestureType. FreeDrag:
Break;
Case GestureType. DragComplete:
Break;
Case GestureType. Flick:
Break;
Case GestureType. Hold:
Break;
Case GestureType. HorizontalDrag:
Break;
Case GestureType. None:
Break;
Case GestureType. Pinch:
Break;
Case GestureType. PinchComplete:
Break;
Case GestureType. VerticalDrag:
Break;
}
}
}
Code sample http://www.daisy123.com /? Page_id = 275 xna input