代码改变世界

WP7备注(6)(TouchLocation接触点与Gesture手势)(XNA)

2011-04-26 15:16  血糯米Otomii  阅读(418)  评论(0编辑  收藏  举报

获取屏幕多点触摸的所有Touch:

TouchCollection touchLocations = TouchPanel.GetState();
foreach (TouchLocation touchLocation in touchLocations)
{
if (touchLocation.State == TouchLocationState.Pressed){}
if (touchLocation.State == TouchLocationState.Moved){}
if (touchLocation.State == TouchLocationState.Released){}
}
 

获取上一时刻的TouchLocation

TouchLocation previousTouchLocation;
bool success = touchLocation.TryGetPreviousLocation(out previousTouchLocation);

TouchLocation的对象拥有Position属性,提供一个相对于屏幕的Vector2对象

-------------------------------------------------------------------------------------------------

设置可用的手势:

TouchPanel.EnabledGestures = GestureType.Tap;

获取手势并处理:

while (TouchPanel.IsGestureAvailable)
{
GestureSample gestureSample = TouchPanel.ReadGesture();
if (gestureSample.GestureType == GestureType.Tap){}
}

GestureSample的对象拥有Position属性,提供一个相对于屏幕的Vector2对象

XNA支持的手势

Tap:手指单击

DoubleTap:手指双击

Hold:手指碰触并固定一段时间

FreeDrag:自由移动手指

VerticalDrag:上下移动手指

HorizontalDrag:左右移动手指

DragComplete:移动结束

Flick:滑过(手指抬起时不停止)

Pinch:缩小和延伸

PinchComplete:缩小和延伸结束