Gesture Recognizers: any plans?

Gesture Recognizers: any plans?

Hi guys!

I am a Cocos2d-x (indie) developer from several mouths and this is my first topic in the forum! :smile:

I am wondering that this awesome framework does not have today modules to handle the touch gestures (as pan, tap, swipe etc.)
My question is: these features are planned to be released in the the next versions of Cocos2d-x?

If not, maybe I can collaborate with you to add these features quickly.
I worked to build C++ classes that implements the following gestures:

  • Long press
  • Tap
  • Swipe
  • Pinch (and Rotation)
  • Pan

Today my classes (written in C++) seems to work well (tested with iOS and Android).
If there is some interest in my work, how the collaboration has to be done?


1 Like

I had always wanted to implement these too. We haven’t done it yet. Collaboration would be great!

Well, how the collaboration should be done?

Should I request a push permission for the cocos2d repository? Or I just create my repo allowing the cocos2d project administrators to evaluate the integration?


@drakon99 would be great!

You would fork the repo, and submit a pull request with your changes.

Thanks slackmoehrle! :smile:
I need time to add comments in the code and to do some other test!
Meanwhile I uploaded a video on Youtube where you can see gestures in action:

The video is recorded from a physical device (iPhone 6)
Green dots represent touch inputs.


I’m happy to help test and integrate.

There is an extension for that, which implemented all your mentioned gestures about 3 years ago.

Of course it needs to be updated (because of the class renaming/addional functionalities in the newer cocos2d-x releases), but you should definitely check out the repository:

Thanks iQD, I will take a look! :wink:
Have you tried to merge your work with Cocos2d?
It is meaningless that each developer must write code for the same functionalities!
It is a waste of time! :frowning:


It’s not my work. It’s from @spalx:

Unfortunately he’s not active anymore since 2013.
I assume merging the extension into the newer versions of cocos2d-x would not be a problem. The question is tho, if the design is still appropriate, as the recognizer class is derived from Layer.
The touch system changed a lot since the introduction of 3.x, so there might be a better approach now, e.g. without deriving from Layer, dropping virtual functions, using delegates and so on.

Besides that, tehre is also a 3.x version of it:

What’s the approach/design with your implementation?

It is, besides from learning, but that’s the problem with code/extensions/contributions scatter around the internet, of which GR is just one example.

Hi iQD

Basically i designed GR classes in this way:

  • There is a base abstract class GestureRecognizer extending cocos2d::Node
  • Each concrete gesture recognizer class extends GestureRecognizer
  • You have to provide a callback to handle the “recognition event”

Here a simple example:

auto pinch = PinchGestureRecognizer::create();
pinch->onPinch = CC_CALLBACK_1(SomeClass::onPinch, this); // imagine we are inside a SomeClass member function

Then the callback looks like this:

void SomeClass::onPinch(PinchGestureRecognizer* recognizer)
    auto status = recognizer->getStatus();
    if (status == GestureStatus::BEGAN)
       CCLOG("Pinch Began");
    else if (status == GestureStatus::CHANGED)
        CCLOG("Pinch changed");
        auto factor = recognizer->getPinchFactor();
        auto angle  = recognizer->getPinchRotation();
        auto trasl  = recognizer->getPinchTraslation();
        // do something with this values
   else if (status == GestureStatus::RECOGNIZED)
        CCLOG("Pinch End");


Therefore no delegate approach, it is similar to the callback of a ui::Button.

Thank you for explaining.
Your design is the same as the one from @spalx, which would make it easy to merge the code/get inspiration from it.

Regarding merging with cocos2d-x. The original thread was also discussing about direct cocos2d-x integration, but unfortunately there was no more incentive about it.

Like I said, let’s create some tests for this and see if we can merge it. I’d love to help.

Discussion continue on this topic please! :slight_smile:

1 Like