WinRT中的触摸手势(使用monogame) [英] Touch gestures in WinRT (using monogame)

查看:122
本文介绍了WinRT中的触摸手势(使用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处理拖动手势的方式有所不同,但是无论我使用此方法还是手动迭代触摸集合,都会遇到相同的问题.

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?

推荐答案

您可以使用

TouchCollection touches = TouchPanel.GetState();

然后是您第一次检测到触摸

and then the first time you detect a touch

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

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

然后检测拖动何时结束

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

您可以使用Vector2.Distance

这篇关于WinRT中的触摸手势(使用monogame)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆