加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Cocos2d-x:2.x与1.x的版本差别集锦

发布时间:2020-12-14 19:14:41 所属栏目:百科 来源:网络整理
导读:原文链接:http://blog.csdn.net/m_leonwang/article/details/17651197 1.版本1.x获取CCTouchDispatcher方法是CCTouchDispatcher::sharedDispatcher(),2.x中被合并到CCDirector中,需要用CCDirector::sharedDirector()-getTouchDispatcher()来获取; 例如,

原文链接:http://blog.csdn.net/m_leonwang/article/details/17651197


1.版本1.x获取CCTouchDispatcher方法是CCTouchDispatcher::sharedDispatcher(),2.x中被合并到CCDirector中,需要用CCDirector::sharedDirector()->getTouchDispatcher()来获取;

例如,1.x注册触屏事件监听方法:CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate
而2.x中要用CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate


2.在1.x中创建层的宏是LAYER_CREATE_FUNC,2.x中改用CREATE_FUNC;版本1.x中创建节点的宏是LAYER_NODE_FUNC,在2.x中用NODE_FUNC。


3.版本2.x用CCArray替换了之前的CCCCMutableArray,1.x中创建数组方法是CCMutableArray<AstarItem*> open = new CCMutableArray<AstarItem*>();

在2.x中方法为CCArray*array = CCArray::create()。

4.CCFileUtils函数使用方法变更,以获取文件路径为例:1.x版本的使用const char* fullpath = cocos2d::CCFileUtils::fullPathFromRelativePath(patha.c_str());而2.x版本的使用const char* fullpath = cocos2d::CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(patha.c_str())。


5.很多对象的创建方法都改成统一的函数命名:create,例如精灵的创建方法在1.x中是:CCSprite *sp = CCSprite::spriteWithFile("himi.png");在2.x中改为:CCSprite *sp = CCSprite::create("himi.png");序列动画创建方法由CCSequence::actions改成CCSequence::create。

6.粒子相关:

在1.x粒子创建和设置自动释放设置
CCParticleSystem *pParticle= CCParticleSystem::particleWithFile("test.plist");
pParticle->setIsAutoRemoveOnFinish(true);
在2.x中改成
CCParticleSystem *pParticle= CCParticleSystemQuad::create("test.plist");
pParticle->setAutoRemoveOnFinish(true);


7.在2.x中去除了CCFileData 类:

原先1.x的CCFileData的使用: cocos2d::CCFileData fileDataClip(const char *pszFileName,const char *pszMode); 2.x中直接使用如下函数代替: CCFileUtils::sharedFileUtils()->getFileData(const char *pszFileName,const char *pszMode,unsigned long *pSize)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读