码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx 3.x 触摸事件

时间:2016-05-23 10:30:38      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

 单点触摸:

 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 触摸事件

标签:

原文地址:http://www.cnblogs.com/H-K-Home/p/5518851.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!