简体   繁体   中英

How to add Swipe Gesture?

I'd like to use the Swipe gesture in Cocos 2dx 3.2. Of course, I used the extension sdk. https://github.com/spalx/cocos2d-x-extensions But it's not works fine for my case. What I would like to do: I used several menu items in the Layer. And I'd like to add the swipe feature on those items. So it should be detect the tap for menu item and swipe for entire Layer. But if I swipe on menu item, then it can't detected the swipe. I tried the extensions. but it's the same. Can I implement my idea? Thank you for your time.

As far as I know, you can't swipe Menu Items, so first of all: 1. Change Menu Items to Sprites and handle it by yourself. 2. My implementation of swipe look like that:

onTouchBegan() {
    getTouch
}

onTouchMoved() {
    //swipe right
    if (touch.getDelta().x > 10) {
        //swiped right
    }
    //swipe left
    if (touch.getDelta().x < 10) {
        //swiped left
    }
    //swipe up
    if (touch.getDelta().y > 10) {
        //swiped up
    }
    //swipe down
    if (touch.getDelta().y < 10) {
        //swiped down
    }
}

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