2011-11-03 65 views
0

我有這樣的:與對象移動直到手指是取消保留或untaped

private void HandleTouchInput() 
{ 
    while (TouchPanel.IsGestureAvailable) 
    { 
    // read the next gesture from the queue 
    GestureSample gesture = TouchPanel.ReadGesture(); 
    switch (gesture.GestureType) 
    { 
    case GestureType.Hold: 
    // left 
    if (gesture.Position.X < 100 && gesture.Position.Y < 100) 
    { 
     ship.Position.X -= 5; 
    } 
    break; 
    } 
} 

(HandleTouchInput是在更新方法)

我怎樣才能repeate代碼在開關直到「手指」是untaped(取消保留)從屏幕?我不想只改變位置一次,我想改變用戶仍然按在確切的位置。由於

+0

我更新的代碼段希望它有助於 –

+2

保持是當你觸摸屏幕1秒。這個手勢只會出現一次。保持你的手指在屏幕上不會每秒開啓一次保持。您可以再次使用Position屬性來確定玩家持有的位置。只要手指在屏幕上,如果您想要做某些事情,則需要使用原始輸入。 – NitWit

回答

0

至於傻子建議,你需要使用原始輸入,例如,像這樣:

protected override void Update(GameTime gameTime) 
{ 
    // TouchPanel.GetState() should be called only once per frame 
    TouchCollection touchCollection = TouchPanel.GetState(); 

    HandleInput(touchCollection); 
} 

private void HandleInput(TouchCollection touchCollection) 
{ 
    if (touchCollection.Count == 0) 
    { 
     return; 
    } 

    TouchLocation touchLocation = touchCollection[0]; 
    Vector2 touchPosition = touchLocation.Position; 

    switch (touchLocation.State) 
    { 
     case TouchLocationState.Moved: 
     case TouchLocationState.Pressed: 
     case TouchLocationState.Released: 
      if (touchPosition.X < 100 && touchPosition.Y < 100) 
      { 
       ship.Position.X -= 5; 
      } 

      break; 

     default: 
      break; 
    } 
} 
+0

不,你放棄了樂趣;) – NitWit