2012-04-19 137 views
1

如何在同一时间读取两个手势。我目前正在开发一款游戏,其中两名玩家应该使用FreeDrag手势。注册两个FreeDrag手势

现在发生的是:

当玩家A开始,他是拖它完美的作品。如果玩家B然后也开始它的FreeDrag手势,则TouchPanel.ReadGesture();不会注册它,直到玩家A的手势完成。

我使用下面的代码:

Initialize()

TouchPanel.EnabledGestures = GestureType.FreeDrag;

Update()

if (TouchPanel.IsGestureAvailable) 
{ 
    GestureSample touch = TouchPanel.ReadGesture(); 

    if (touch.GestureType == GestureType.FreeDrag) 
    { 
     if (touch.Position.Y > GraphicsDevice.Viewport.Height/2) 
     { 
      //logic Player A here 
     } 
     else 
     { 
      //logic Player B there 
     } 
    } 
} 
+0

您好,我注意到您参与了“医疗IT”堆栈交换,并认为您可能对此建议感兴趣 - > [医疗行业](http://area51.stackexchange.com/proposals/41370/healthcare-行业?referrer = kaxVuDLRWM_Z_15aCbzplg2) – 2012-06-26 15:15:46

回答

0

您MSDN文档中有一个例子:

http://msdn.microsoft.com/en-us/library/ff827740.aspx

// get any gestures that are ready. 
while (TouchPanel.IsGestureAvailable) 
{ 
    GestureSample gs = TouchPanel.ReadGesture(); 
    switch (gs.GestureType) 
    { 
     case GestureType.VerticalDrag: 
      // move the poem screen vertically by the drag delta 
      // amount. 
      poem.offset.Y -= gs.Delta.Y; 
      break; 

     case GestureType.Flick: 
      // add velocity to the poem screen (only interested in 
      // changes to Y velocity). 
      poem.velocity.Y += gs.Delta.Y; 
      break; 
    } 
} 
+0

是的,我读到了。除了它没有同时注册两个手势(它基本上与我提供的示例相同)。 – 2012-04-20 16:02:03

0

你不能,FreeDrag是不是多点触摸姿态,你应该尝试使用TouchLocationTouchCollection这让你检测的多点触控。不幸的是,您不能使用您在TouchPanel.EnabledGestures中声明的默认手势。