WP7 XNA game development (IV. Input)

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.