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

原文链接: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)

相关文章

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