Generic gesture recognizer for cocos2d-x


#1

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):
https://bitbucket.org/x264/gesturerecognizerexample

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.

Regards,


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

Great work, thnk.


#3

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.

Justin


#4

This one: https://bitbucket.org/x264/gesturerecognizerexample
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?


#5

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.


#6

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

Hope that helps.


#7

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


#8

Hi,
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?
Thanks


#9

Just “BAD …”?


#10

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!