简体   繁体   中英

XNA wp7 gesture detection issue

I have to use both type of input in my app (gestures and simple touch). And i got a problem with it. For example i use double tap gesture and before it detected i have one detection of simple touch. This in not that way i expect, because simple touch has its own logic, which brings me lot of problems. The same issue with Drag, before detecting drag again first decetced simple touch. How can i handle gestures without handling simple touch logic. Here the way im trying to do that:

TouchPanel.EnabledGestures = GestureType.DoubleTap | GestureType.VerticalDrag;
        while (TouchPanel.IsGestureAvailable)
        {
            isGesture = true;
            GestureSample gestureSample = TouchPanel.ReadGesture();
            switch (gestureSample.GestureType)
            {
                case GestureType.DoubleTap:

                    //some logic
                    break;
                case GestureType.HorizontalDrag:
                    //some logic
                    break;
            }
        }


        if (Consts.TouchCollection.Count == 1) 
        {
            var touch = Consts.TouchCollection[0]; //here needed only first touch

            switch (touch.State)
            {
                case TouchLocationState.Pressed:
                     //This one called first if used double tap

                    break;
                case TouchLocatiomState.Moved:
                    //smth
                    break;
                case TouchLocationState.Released:
                    //smth
                    break;
            }
        }

When double tap gesture is used this code calls Pressed -> Released -> DoubleTap -> Pressed I want to handle only double tap case. how to fix this? Feel sorry for my english, hope my question is clear. Any help will be appreciated

To avoid handling the simple touch event after handling the gestures, add a Boolean flag that you set at the beginning of your touch handling to true , lets call it handleSimpleTouch . If you process a gesture, set handleSimpleTouch to false. Then before you process a simple touch, check the valu of handleSimpleTouch , if it's true, then process normally, otherwise, do nothing.

我得出的结论是,唯一可行的方法是不使用TouchPanel.EnabledGestures编写自己的输入。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM