2014-01-05 33 views
0

我正在使用Monogame爲Windows Phone 8創建遊戲。如圖所示,我想使用兩個屏幕控制器分別控制坦克的移動以及其射速。同步手勢檢測使用D Pad&Firing Windows Phone 8的XNA(Monogame)

但是,我一次只能控制一個。我無法同時移動坦克並開火。我正在使用一個輸入類來管理輸入。對於每個輸入我都有

input.AddTouchGestureInput(playerMoveDrag, GestureType.FreeDrag, 
     joystickMove.BoundingBoxRect); 

input.AddTouchTapInput(playerFireTap, joystickFire.BoundingBoxRect, true); 

那麼,我該如何檢測兩個單獨的手勢(自由拖動D墊,並點擊防火墊)同時?

enter image description here

回答

0

我想通了。沒有我最初想象的那麼難!如果有人在同一條船上,這是我的解決方案。

我們不使用像FreeDrag這樣的手勢,而是讀取原始觸摸數據。 Windows Phone 8硬件似乎最多支持8個同時觸摸點。

因此,我的部分代碼檢測屏幕上任何觸摸的位置。

public void GetTouchPoints() 
    { 
     TouchCollection touches = TouchPanel.GetState(); 

     for (int i = 0; i < touches.Count; i++) 
     { 
      Vector2 position = touches[i].Position; 

      if (thumbstickMove.IsPointInside(position)) 
      { 
       thumbstickMove.TouchLocation = position; 
      } 

      if (thumbstickFire.IsPointInside(position)) 
      { 
       thumbstickFire.TouchLocation = position; 
      }  
     } 
    }