问题
I currently have the following code:
internal void HandleTouch()
{
    TouchPanel.EnabledGestures = GestureType.DragComplete | GestureType.FreeDrag;
    while (TouchPanel.IsGestureAvailable)
    {
        GestureSample gesture = TouchPanel.ReadGesture();
        if (gesture.GestureType == GestureType.DragComplete)
        {
            MyAction(gesture.Delta.X, gesture.Delta.Y);
        }
        else if (gesture.GestureType == GestureType.FreeDrag)
        {
            OtherAction();
        }
    }
}
The problem that I have is that the Delta is always 0.  I read somewhere that Monogame deals with dragging gestures differently, but whether I use this method, or manually iterate through the touch collection, I get the same issue.
How can I change this so that I get the correct delta value?
回答1:
You can achieve the same thing using
TouchCollection touches = TouchPanel.GetState();
and then the first time you detect a touch
touches.First().State == TouchLocationState.Pressed || touches.First().State == TouchLocationState.Moved
you save the location touches.First().Position
Then to detect when the drag is over
touches.First().State == TouchLocationState.Released
you can compute the Delta using Vector2.Distance
来源:https://stackoverflow.com/questions/20281147/touch-gestures-in-winrt-using-monogame