Kevin
Kevin

Reputation: 403

Issues with XNA Gestures

My XNA Gestures are not working. I am trying to create a weather app that will pull up a 7-day forecast when swiped up, and pull it away when swiped down. The left/right gestures are for switching pages. What am I doing wrong here? My app, when tested, gets confused and thinks every gesture is a left/right one or no gesture at all, sometimes. Why won't it detect up my up/down gestures, and why are the left/right ones so inaccurate?

Note: GestureText.Text is just for debugging.

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

Upvotes: 1

Views: 172

Answers (2)

HumusFoodz
HumusFoodz

Reputation: 1

Your up/down gestures didn't get noticed since you're using gesture.Delta.X when you should have been using gesture.Delta.Y. The VerticalDrag gesture doesn't detect the horizontal changes.

Also the conditions for up/down detection should be the opposite way as Vector2.Zero is in the upper left corner

Upvotes: 0

Feusp
Feusp

Reputation: 99

My suggestion will be to avoid using Gestures at all. There are too many problems with them and the best way to solve this issue is to write your own gestures using TouchCollection

Upvotes: 1

Related Questions