转载于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
CCString* str = CCString::createWithFormat("%s.png","picture");After
std::string str = StringUtils::format("%s.png","picture");
CCDictionary usage changes
After
CCDictionary* dict = CCDictionary::createWithContentsOfFile("name.plist");CCArray* arr = (CCArray*) data->objectForKey("Levels");
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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。