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.
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
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.
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.
– 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.
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.
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 🙂