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 of CC has 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");
					std::string str = StringUtils::format("%s.png","picture");

CCDictionary usage changes

				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 ="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);;
6 sprites->count(); sprites.size();

Below are additional comments provided by Fradow

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


		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.

Posted in Tutorials Tagged with: , , , ,
9 comments on “cocos2d-x v2 to v3 mapping guide
  1. Rajan says:

    great..just update more and more

  2. Sachin Garg says:

    Great Effort. Many thanks.

    Isn’t it better that you (or me ) make some sort of open document so that everyone can contribute?

    • Saket Sinha says:

      Great thought Sachin, any ideas? cocos2d-x discuss has these info and everyone can contribute, but it is scattered at the moment so I though this. If you want to blog let me know, most welcome to add you as an author here :)

  3. Miguel Ferreira says:

    There is a problem in “CCArray Usage changes”

    CCArray count() is not equivalent to Vector capacity().
    CCArray count() is equivalent to Vector size().

  4. AlanDuo says:

    Great work!
    Since lots of tutorial available are for v2.x only,
    this article helps many cocos2d-x beginners.
    Thank you very much!

  5. helios says:

    awesome, keep it up. im using this as my reference :)

2 Pings/Trackbacks for "cocos2d-x v2 to v3 mapping guide"
  1. […] 本文大部分内容来自对这篇文章的翻译《Cocos2d-x v2 to v3 mapping guide》。 […]

Leave a Reply

Your email address will not be published. Required fields are marked *


Join 1 other subscriber