2012-04-19 72 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中聲明的默認手勢。