【问题标题】:Issues with XNA GesturesXNA 手势问题
【发布时间】:2013-12-22 14:53:24
【问题描述】:

我的 XNA 手势不起作用。我正在尝试创建一个天气应用程序,它会在向上滑动时拉出 7 天的预报,并在向下滑动时将其拉开。左/右手势用于切换页面。我在这里做错了什么?我的应用程序在测试时会感到困惑,有时会认为每个手势都是左/右手势或根本没有手势。为什么它不会检测到我的上/下手势,为什么左/右的手势如此不准确?

注意:GestureText.Text 仅用于调试。

public MainPage()
{
    InitializeComponent();
    TouchPanel.EnabledGestures = GestureType.VerticalDrag | GestureType.HorizontalDrag;
}

private void gestures(object sender, ManipulationCompletedEventArgs e)
{
    while (TouchPanel.IsGestureAvailable)
    {
        GestureSample gesture = TouchPanel.ReadGesture();
        switch (gesture.GestureType)
        {
            case GestureType.HorizontalDrag:
                float a = gesture.Delta.X;
                int b = (int)a;
                if (b > 0)
                {
                    gestureText.Text = "Left";
                }
                if (b < 0)
                {
                    gestureText.Text = "Right";
                }
                break;
            case GestureType.VerticalDrag:
                float c = gesture.Delta.X;
                int d = (int)c;
                if (d > 0)
                {
                    gestureText.Text = "Up";
                }
                if (d < 0)
                {
                    gestureText.Text = "Down";
                }
            break;
        }
    }

【问题讨论】:

  • 您是否尝试删除HorizontalDrag 并查看您的游戏是否检测到VerticalDrag
  • 按照下面的建议写了我自己的手势。工作得很好并解决了。

标签: c# windows-phone-8 xna


【解决方案1】:

我的建议是完全避免使用Gestures。它们存在太多问题,解决此问题的最佳方法是使用TouchCollection编写自己的手势

【讨论】:

    【解决方案2】:

    您的向上/向下手势没有引起注意,因为您使用的是 gesture.Delta.X,而您本应使用 gesture.Delta.YVerticalDrag 手势不检测水平变化。

    向上/向下检测的条件也应该与Vector2.Zero在左上角相反

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-13
      • 1970-01-01
      • 2010-10-16
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      相关资源
      最近更新 更多