Generic gesture recognizer for cocos2d-x

Generic gesture recognizer for cocos2d-x
0.0 0


Hi everyone,

I’ve written a simple library for recognizing gestures for cocos2d-x. Now I want to share it if anyone finds it helpful.
The classes are in C++ and platform independent, of course cocos2d-x is required. Currently, this lib works with cocos2d-x v3.x, but I think with some simple modifications, it can work with v2.x.

Gestures supported: Tap, Double tap, Long press, Pan, Pinch, Rotation, Swipe.

The source is located here (with example included):

The example is tested on iOS only, but I hope it will work on other platforms as well.

If anyone can port it to work with cocos2d-x v2.x, please let me know.


How to achieve the Tap, Pinch/Zoom In /Out effect?

Great work, thnk.


This looks awesome.

One suggestion I have is that instead of having a callback interface that you need to implement, use std::function for the callbacks, that way you can bind c functions, class members, or even lambda functions as a callback.



This one:
Seems to be good but I has some compiling errors with cocos 2dx 3.4

jni/../../Classes/HelloWorldScene.cpp:66: error: undefined reference to 'TSimpleGestureRecognizer::TSimpleGestureRecognizer()'
jni/../../Classes/HelloWorldScene.cpp:110: error: undefined reference to 'NodeContainsPoint(cocos2d::Node*, cocos2d::Vec2 const&)'
jni/../../Classes/HelloWorldScene.cpp:123: error: undefined reference to 'NodeContainsPoint(cocos2d::Node*, cocos2d::Vec2 const&)'
jni/../../Classes/HelloWorldScene.cpp:140: error: undefined reference to 'NodeContainsPoint(cocos2d::Node*, cocos2d::Vec2 const&)'
jni/../../Classes/HelloWorldScene.cpp:161: error: undefined reference to 'NodeContainsPoint(cocos2d::Node*, cocos2d::Vec2 const&)'

Someone is using this?


For 2.x there are these gesture extensions:

I was thinking about porting it to 3.x (when I’m finished with my current contract), but will look over yours before I commit to that.


NodeContainsPoint() is declared in Utils.h and is defined in Utils.cpp. You need to include the .cpp file in your

Hope that helps.


Thank you very much, it was my fault, now it works :smile:
Very nice!


this is an old post but I try:
I have found a problem with this code. I use this gesture recognition on game scene in game layer and in interface layer separatedly. When I try to return to menu scene I get an error “BAD…”
The autor of this code have same time to help me in this investigation?


Just “BAD …”?


Hi, I have currently solved using the gesture code only in the interface and forwarding specific events to the game.
The project must finish as soon as possible, but as soon as I can I prepare the sample code with the error. Thank you!