cocos2d-x CCTouchDispatcher - no sharedDispatcher

瘦欲@ 提交于 2019-12-06 21:11:46

问题


I'm currently porting an ObjC cocos2d game to cocos2d-x, but I'm encountering some problems when trying to create a registerWithTouchDispatcher method, at the moment I'm doing

void GameLayer::registerWithTouchDispatcher()
{
    CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,0,true);
}

but this gives an error 'No member named sharedDispatcher' in cocos2d::CCTouchDispatcher'.

Is there another way that this must be done in cocos2d-x?


回答1:


If you are using 2.0, they have been merged in to CCDirector. please use

            CCDirector::sharedDirector()->getTouchDispatcher()



回答2:


use those code instead ccdirector. put the code to cclayer init function.

setTouchMode(kCCTouchesOneByOne);

registerWithTouchDispatcher();



回答3:


In the cocos2d-x you can do like this.

CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,0);


来源:https://stackoverflow.com/questions/11264191/cocos2d-x-cctouchdispatcher-no-shareddispatcher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!