Cocos2d-x v2和v3对照手册
转载于http://www.redtgames.com/blog/cocos2d-x-v2-to-v3-mapping-guide/ |
# | 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.
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!