cocos2d-iOS - 手势识别器
问题描述
有没有人设法让手势识别在 cocos-2d 中工作?
Has anyone managed to get the gesture recognition working in cocos-2d?
我在这里读过一篇声称已经实现的帖子,这里:http:///www.cocos2d-iphone.org/forum/topic/8929
I have read a post here that claimed to have achieved it, here: http://www.cocos2d-iphone.org/forum/topic/8929
我从这里的 git hub 打了补丁:https://github.com/xemus/cocos2d-GestureRecognizers/blob/master/README
I patched from the git hub here: https://github.com/xemus/cocos2d-GestureRecognizers/blob/master/README
我做了一个CCSprite
的子类(它是CCNode
的子类):
I made a subclass of CCSprite
(which is a subclass of CCNode
):
委托方法:
我的点击事件永远不会被调用.
My tap event never gets called.
有人搞定这个吗?手动进行手势识别进行滑动检测有多难?
Has anyone got this working? How difficult is it to do gesture recognition manually for swipe detection?
推荐答案
您需要将手势识别器附加到链上"的东西上.不要将它们附加到单个节点;将它们附加到 UIView(即 [[CCDirector sharedDirector] openGLView]).
You need to attach the gesture recognizer to something "up the chain". Don't attach them to the individual nodes; attach them to the UIView (i.e., [[CCDirector sharedDirector] openGLView]).
这就是我所做的:
此特定代码用于场景控制器的超类中,因此选择器的目标被硬编码为self",但您可以轻松地将其抽象为传入的对象.此外,您可以推断上述内容以轻松创建轻击、捏合等手势识别器.
This particular code is used in a superclass for scene controllers, so the target for the selector is hard-coded to "self", but you could easily abstract that to a passed-in object. Also, you could extrapolate the above to easily create gesture recognizers for taps, pinches, etc.
在控制器的子类中,我只是这样做:
In the subclass for the controller, then, I just do this:
这篇关于cocos2d-iOS - 手势识别器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!