COCOS-多点触摸

对于cocos2dx 2.x版本的多点触摸的机制,主要实现代码如下:

// 需要重写的函数, 复数形式
void cctouchesBegan(CCSet *ptouches,CCEvent *pEvent);  // 注意返回类型是void
void cctouchesMoved(CCSet *ptouches,CCEvent *pEvent);
void cctouchesEnded(CCSet *ptouches,CCEvent *pEvent);

// 首先需要注册触摸
CCDirector::sharedDirector()->getTouchdispatcher()->addStandardDelegate( this,0);
// 最后需要移除触摸
CCDirector::sharedDirector()->getTouchdispatcher()->removeDelegate(this);


对于cocos2dx 3.x版本的多点触摸的机制,主要实现代码如下:

// 需要实现的回调函数,复数形式
void ontouchesBegan(const std::vector<Touch*>& touches,Event *unused_event);
void ontouchesMoved(const std::vector<Touch*>& touches,Event *unused_event);
void ontouchesEnded(const std::vector<Touch*>& touches,Event *unused_event);
void ontouchesCancelled(const std::vector<Touch*>&touches,Event *unused_event);

// 首先需要开启监听
auto listener = EventListenerTouchAllAtOnce::create();
listener->ontouchesBegan = CC_CALLBACK_2(GameLayer::ontouchesBegan,this);
listener->ontouchesMoved = CC_CALLBACK_2(GameLayer::ontouchesMoved,this);
listener->ontouchesEnded = CC_CALLBACK_2(GameLayer::ontouchesEnded,this);
_eventdispatcher->addEventListenerWithSceneGraPHPriority(listener,this);
// 最后需要移除监听
_eventdispatcher->removeAllEventListeners();

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...