在WinRT中触摸手势(使用monogame)

时间:2013-11-29 08:18:21

标签: c# xna windows-runtime monogame

我目前有以下代码:

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();
        }
    }
}

我遇到的问题是Delta始终为0.我在某处看到Monogame处理拖动手势的方式不同,但无论我使用此方法,还是手动迭代触摸集合,我都会得到相同的问题。

如何更改此值以便获得正确的delta值?

1 个答案:

答案 0 :(得分:0)

您可以使用

实现相同的目标
TouchCollection touches = TouchPanel.GetState();

然后第一次检测到触摸

touches.First().State == TouchLocationState.Pressed || touches.First().State == TouchLocationState.Moved

您保存位置touches.First().Position

然后检测阻力何时结束

touches.First().State == TouchLocationState.Released

您可以使用Delta

计算Vector2.Distance
相关问题