GB2ShapeCache for cocos2d-x

GB2ShapeCache for cocos2d-x
0.0 0



Is is possible to have this loaded for box2d translated to C++ and integrate it to coco2d-x. I think this would bring a lot of value for the framework since this tool PhysicsEditor ( is used by a lot of developers.

I also attached the source files which are available on that site. (1.3 KB) (2.6 KB)


I don’t think integration would be such a good idea because other developers might use their own system for communicating with Box2D.

It’s rather something you’d put in your local app code instead of in Cocos2d-x, I guess. What stops you from doing the port to C++ and just use it? Doesn’t look like it would be hard to pull it off, but if you need any help, just shout :slight_smile:


Yes I need help :slight_smile:
I don’t know Objective C, that’s why I choose cocos2d-x.
I don’t necessary need this loader to be places in the coco2d-x folder. Can you help me with translating it ?



I don’t know Obj-C either :stuck_out_tongue: but still succeeded in converting some source files before. Currently I don’t have much time (perhaps in a few hours), but there’s a few things I can tell you about it that should definitely help:

  • NSObject = CCObject in Cocos2d-x (every NSXxxXxx class translates to CCXxxXxx, so NSMutableDictionary is CCMutableDictionary and so on)
  • interface is just a class in C*+
  • # import is # include
  • I’m not sure about the* and - methods, but I guess it means that + is supposed to be protected and - public methods or variables
  • Evertyhing after the semicolon ( “:” ) is just a set of arguments in a weird notation, they can be translated to C*+ quite straight
  • Methods and variables in the .h file are seperate, but they are actually part of a C*+ class
  • The stuff between brackets ( “[” and “]” ) are supposed to be properties, but they’re actually just some kind of methods
  • [array objectAtIndex:0] means something like (array~~>getObjectAtIndex)
    ~~ the init and dealloc methods are like a constructor and destructor in C++ classes (although Cocos2d-x replaces init with bool init() methods)
  • [super init] is just like calling a constructor from a base class, nothing too difficult there

  • means class method, it can translated to static method in c++;
  • menas object method, don’t add static.


i’m converting it now,but i met some problems

        // iterate through the fixtures
        NSArray *fixtureList = [bodyData objectForKey:@"fixtures"];
        FixtureDef **nextFixtureDef = &(bodyDef->fixtures);

        for(NSDictionary *fixtureData in fixtureList)

this part, which translate to c*+
CCArray* fixtureList = ));
CCMutableArray<CCString*>::CCMutableArrayIterator iter;
FixtureDef **nextFixtureDef = &;
for ; iter != fixtureList->end;*+iter)

has a fatal error with the CCArray, i also try the CCMutableArray but the result are same.

i just need one more step then i’ll succeed in translate this
can somebody help me?


Hi guys !

We looked for that stuff at school, and we landed here.
So we tried to convert it by ourselves, and it seems that we’ve succeed!

So if some of you are interested, here it is !


This is awesome. Thank you @Mathias!


Hi guys!

I’m using cocos2d-x 0.11.0 and I was trying to use this class.
Unfortunately, when I compile it, I’m receiving this error:

jni/…/…/Classes/GB2ShapeCache.cpp:121: error: ‘class cocos2d::CCMutableDictionary<std::basic_string<char, std::char_traits, std::allocator >, cocos2d::CCObject*>’ has no member named ‘getMap’

Do you know why it is happening?



I had the same error. I think there was a change in CCDictionary recently. I modified the code a little bit and it is working great now. Here is my version.


Thanks @Brandon

Now I have problems in:

GB2ShapeCashe::sharedShapeCache()->addFixturesToBody( body, “itemname” );

Note: I’m developing for iphone


Sorry, I was doing one thing wrong.

Thanks @Brandon!


Glad to see you figured it out @jefferson.


Yeap, the last update (or maybe the one before) removed the getMap function from CCDictionary.
You just have to copy/paste it from the old version.


Hi All,

I have updated the GB2ShapeCache reader class to work with the newest branch of cocos2d-x, 2.0. This handles the deprecation of CCMutableDictionary and CCMutableArray. Check out the project page on my site for download or links to the source on github:


Thanks for doing that Chris. You saved me some more time!