对于Windows Phone7来说与用户的交互方法主要有三种:手势、按键、触控和一些传感器的信号(如重力感应等,对于最后一种,在一起学Windows Phone7开发(十四. Device)中已经详细介绍过了)所以XNA游戏所能用到的交互方式也是一样的。但对于XNA来说与Windows phone7是有很大区别的。其主要的函数在Microsoft.Xna.Framework.InputMicrosoft.Xna.Framework.Input.TouchPanel

一.按键:对于按键来说,其实可控的也就只有Back键,其它的两个键是不受控的。

public void Update()

        {

             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)//这个是系统填加的

               {

                                     //…

}

}

 

二.触控:状态也很少,只有MovePressRelease这么几种。

TouchCollection touchState = TouchPanel.GetState();

foreach (TouchLocation location in touchState)

      {

        switch (location.State)

        {

          case TouchLocationState.Pressed:

            break;

          case TouchLocationState.Moved:

            break;

          case TouchLocationState.Released:

            break;

        }

      }

 

三.手势:可以通过手在屏幕上的不同动作来触发不同应用和触控很相似,但是比其状    态要多很多,并且需要指定。

TouchPanel.EnabledGestures = GestureType.FreeDrag;//用来指定手势,必须要先设定,否则分报错

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;

                    }

                }

 

}

 

 

示例代码 http://www.daisy123.com/?page_id=275 xna input

 

posted on 2010-11-09 10:45  小镇  阅读(2550)  评论(5编辑  收藏  举报