cocos2dx 3.x 触摸事件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cocos2dx 3.x 触摸事件相关的知识,希望对你有一定的参考价值。
单点触摸:
bool onTouchBegan(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
void onTouchMoved(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
void onTouchEnded(cocos2d::Touch *pTouch, cocos2d::Event *pEvent);
多点触摸:
void onTouchesBegan(const std::vector<cocos2d::Touch *>& touches, cocos2d::Event *unused_event);
void onTouchesMoved(const std::vector<cocos2d::Touch *>& touches, cocos2d::Event *unused_event);
void onTouchesEnded(const std::vector<cocos2d::Touch *>& touches, cocos2d::Event *unused_event);
触摸注册:
EventDispatcher *dispatcher = Director::getInstance()->getEventDispatcher();
EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = CC_CALLBACK_2(MyLayer::onTouchBegan,this);
listener->onTouchMoved = CC_CALLBACK_2(MyLayer::onTouchMoved,this);
listener->onTouchEnded = CC_CALLBACK_2(MyLayer::onTouchEnded,this);
dispatcher->addEventListenerWithSceneGraphpriority(listener,this);
listen->setSwallowTouches(true);
setSwallowTouches用于设置是否吞没事件,也就是当某个触摸事件回调的时,截断该事件,让它不能继续传递给其他人。同时2个层,上层写了之后,下面的层获取不到点击事件.
以上是关于cocos2dx 3.x 触摸事件的主要内容,如果未能解决你的问题,请参考以下文章