我有这个:
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在Update方法中)
如何在屏幕上取消(取消)“手指”之前,我可以在开关中重复代码?我不想只改变一次位置,我想改变用户仍然按下确切的位置。感谢
答案 0 :(得分:0)
正如NitWit建议的那样,你需要使用原始输入,例如:
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;
}
}