Touch gestures in WinRT (using monogame)

谁都会走 提交于 2019-12-25 05:34:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!