Chrotov Kofma
Chrotov Kofma

Reputation: 13

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.

Upvotes: 1

Views: 451

Answers (1)

sortris
sortris

Reputation: 197

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

Upvotes: 0

Related Questions