Cocos2d-x v2和v3对照手册

转载于http://www.redtgames.com/blog/cocos2d-x-v2-to-v3-mapping-guide/


cocos2d-x v2 to v3 mapping guide

So I started my next project and decided to use cocos2d-x v3. As soon as I started migrating my common classes,I realized that there are significant changes not only to the naming convention but also usage of some of the classes such as “CCDictionary”,“CCArray”,“CCString” and many more. I will list the transition mapping from v2 to v3 below as I come across. Please feel free to leave a comment if I have missed out anything.

cocos2d-x v2 to v3 mapping

The list below maps the transition which has been made in cocos2d-x framework recently. This are minor changes to naming convensions and the underlying logic is the same.

In short the use ofCChas been removed.

# v2 v3
1 CCAction Action
2 CCPoint Point
3 CCAnimation Animation
4 CCSprite Sprite
5 cclabel Label
6 Ccmenu Menu
7 CCObject Ref
8 CCNode Node
9 CCScene Scene
10 cclayer Layer
11 CCSpriteBatchNode SpriteBatchNode
12 CCTMXTiledMap TMXTiledMap

cocos2d-x v2 to v3 mapping

The changes below are more significant since the underlying usage has been changed as well.

# v2 v3
1 CCDictionary ValueMap
2 CCArray ValueVector
3 CCString Value

CCString usage changes

Before
					
				CCString* str = CCString::createWithFormat("%s.png","picture");
After
					
				std::string str = StringUtils::format("%s.png","picture");

CCDictionary usage changes

Before
				
CCDictionary* dict = CCDictionary::createWithContentsOfFile("name.plist");CCArray* arr = (CCArray*) data->objectForKey("Levels");
After
				


std::string path = FileUtils::getInstance()->fullPathForFilename("name.plist");ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(path);ValueVector arrLevels = data.at("Levels").asValueVector();

CCArray Usage changes

# v2 v3
1 CCArray* sprites Vector<Sprite *> sprites
2 sprites->addobject(sprite); sprites.pushBack(sprite)
3 sprites->removeObject(sprite); sprites.eraSEObject(sprite);
4 sprites->removeObjectAtIndex(i); sprites.erase(i);
5 sprites->objectAtIndex(i); sprites.at(i);
6 sprites->count(); sprites.size();

Below are additional comments provided byFradow

touches Usage changes

# v2 v3
1 ccTouchBegan onTouchBegan
2 ccTouchMoved onTouchMoved
3 ccTouchEnded onTouchBegan

EGLView Usage changes

# v2 v3
1 CCEGLView::sharedOpenGLView(); Director::sharedDirector()->getopenGLView();

CCTime Usage changes

# v2 v3
1 cc_timeval timeval
2 CCTime::gettimeofdayCocos2d gettimeofday
3 CCTime::timersubCocos2d getTimeDifferenceMS

Sample

		

static inline float getTimeDifferenceMS(timeval& start,timeval& end){return ((((end.tv_sec - start.tv_sec)*1000.0f + end.tv_usec) - start.tv_usec) / 1000.0f);}

Labels Usage changes

# v2 v3
1 cclabelTTF Label

I will keep updating this article as I come across any changes which are not obvIoUs. Please help me in doing so by providing some Feedback and anything I have missed. Thanks for reading.

相关文章

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