0

I'm having trouble in developing my windows phone app. It's a game and I'm using XNA.

Here one of the Navigation Page:

navigation page

The problem is that in the top left the "back" button is at the same place on the page before this one. So when I tap the back button, it doesn't lead me to the previous page but to the first one. (sometimes if I click fast enought it leads me to the previous one). As it works sometimes, I think the error doesn't come from my code. I think as the back_button is at the same place on both pages, it update too fast and the "touch_event" stay for too long maybe. I don't know how to solve this.
There is how I catch the button click:

TouchPanelCapabilities touchCap = TouchPanel.GetCapabilities();

if (touchCap.IsConnected)
{
    TouchCollection touches = TouchPanel.GetState();

    if (touches.Count >= 1)
    {
        Vector2 PositionTouch = touches[0].Position;
        return (Mouseclik((int)PositionTouch.X, (int)PositionTouch.Y));
    }
}

return (Screen.ChooseLevelScreen);

3 Answers 3

1

You need something like this:

if (touches.Count >= 1)
    if (touches[0].State == TouchLocationState.Released)
    {
        Vector2 PositionTouch = touches[0].Position;
        return (Mouseclik((int)PositionTouch.X, (int)PositionTouch.Y));
    }

Usually, a tap is detected when you release the touch, not while you are pressing it, in this way you are sure that you detect it only once.

0
0

Poll for when your finger is released as opposed to clicked. That way when you remove your finger from the touch button it will only be registered once and not the x amount of times your finger was still on the button and the loop was carried out.

see TouchLocationState.Released at

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.touch.touchlocationstate.aspx
1
  • I'm gonna try this, any idea about wich method i have to use ?
    – Gabson
    Commented Nov 6, 2013 at 13:02
0

you need TouchLocationState.Released

http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.touch.touchlocationstate.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.