Introduction to some great ios gesture recognition libraries (cocos2d)

I happen to need a gesture feature for my recent game so I did some search on Internet and tried some 3rd party libraries as well and finally find the solution. And I would like to share the search result with those who may be interest in.

– Sometimes the basic stuffs will just meet our requirement:

1. Using the old-fashioned way by yourself
This is absolutely the most basic method to achieve gesture recognition in cocos2d –
using the “CCTargetedTouchDelegate” && “CCStandardTouchDelegate” and handle your own recognition logic in the “touchBegan – touchMoved – touchEnded” methods.

ref link: http://www.cocos2d-iphone.org/wiki/doku.php/tips:touchdelegates

2. A implementation of the old-fashioned way – GestureDetection Class (By Metric)
Metric created this GestureDetection classes with some different gesture methods already built in.
It now supports gestures: Swipe (left, right, up, down), square, circle, X-mark

ref link: http://www.cocos2d-iphone.org/forum/topic/2527

Here is a simple demo I made using the GestureDetection class:

– UIGestureRecognizer is a cool thing and you can use it in cocos2d as well:

3. Using UIGestureRecognizer in a cocos2d’way (1) – CCGestureRecognizer (By xemus)

xemus created this CCGestureRecognizer class that brings UIGestureRecognizer to cocos2d world.
It allow’s you to use the gestures defined in the UIGestureRecognizer.
But, you’ll need to change the cocos2d source code (CCNode and CCLayer) before you use the class.

ref link: http://www.cocos2d-iphone.org/forum/topic/8929

4. Using UIGestureRecognizer in a cocos2d’way (2) – SFGestureRecognizers (By Krzysztof Zabłock)
Krzysztof Zabłock created this SFGestureRecognizers class which also also you to use the gestures defined in the UIGestureRecognizer.
You don’t need to change the cocos2d source code since it used category and the code works with both
1.0 and 2.0 cocos2d version.

ref link: http://www.merowing.info/2012/03/using-gesturerecognizers-in-cocos2d/
ref link: https://github.com/krzysztofzablocki/CCNode-SFGestureRecognizers

Demo:

– If you need to recognize more complex gestures and even custom gestures, here you go:

5. $1 Unistroke Recognizer – MCGestureRecognizer (By Malcom)

Malcom created this MCGestureRecognizer class way back in 2009. It’s a Objective-C
implementation of the $1 Unistroke Recognizer – a simple gesture recognition algorithm.
It includes 16 different recognized gestures and you can easily add more.

ref link: http://depts.washington.edu/aimgroup/proj/dollar/

Actually, the source code is really hard to find since the the host site was down and I happened to find the source code file from some old project from the Internet and then made some changes to the source so that it can work with cocos2d. The recognize result is not good at all (Maybe that’s because I haven’t spent to much time on it):

6. N Dollar Unistroke Recognizer – WTMGlyphRecognizer (By Brit Gardner)
Brit Gardner created this WTMGlyphRecognizer class which is an iOS implementation of the [N Dollar Gesture Recognizer].
And there is also a java app for creating shapes and exporting them as JSON files.

ref link: http://lucalaiho.altervista.org/joomla/shape-editor
ref link: https://github.com/britg/MultistrokeGestureRecognizer-iOS

I made some changes to source code and created a CCLayer object instead of the UIView stuff, you can see it in this demo:

All the solutions may have its pros/cons, you can decide which one to take according to the requirement of your game 🙂

To Download Page…

☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
If you feel all the stuffs in this site helped you a lot and you can get a game I made 🙂

☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆