在Cocos2d 3.0中检测长按

时间:2014-04-04 11:55:15

标签: ios iphone cocos2d-iphone

我想在我的游戏中检测到长按触摸,但CCTargetedTouchDelegate中的问题Cocos2d 3.0不再存在以实现其delegates。我怎么能这样做?

2 个答案:

答案 0 :(得分:2)

CCTargetedTouchDelegate仍然存在,但已重命名为CCTouchOneByOneDelegate(仅对2.1 +有效)

似乎触控已移至CCResponder。而不是委托,它似乎期望你继承它并覆盖触摸方法:

– touchBegan:withEvent:
– touchMoved:withEvent:
– touchEnded:withEvent:
– touchCancelled:withEvent:

但是长按,我可能仍会使用UILongPressGestureRecognizer

答案 1 :(得分:0)

http://www.cocos2d-x.org/attachments/1782/XTLayer.zip下载此文件。它实现了不同的手势

void xtTapGesture(CCPoint position) {}
virtual void xtDoubleTapGesture(CCPoint position) {}
virtual void xtLongTapGesture(CCPoint position) {}
virtual void xtSwipeGesture(XTTouchDirection direction, float distance, float speed) {}

您在头文件中扩展cclayer。将其替换为XTLayer并将所有触摸事件替换为xt而不是cc。

您可以在http://www.cocos2d-x.org/forums/6/topics/23011

上获得更多详细信息 希望这会有所帮助。