Cocos2d-x v2和v3对照手册

前端之家收集整理的这篇文章主要介绍了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();
@H_770_301@ 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
@H_770_301@ 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.

原文链接:https://www.f2er.com/cocos2dx/345520.html

猜你在找的Cocos2d-x相关文章