Using LevelHelper without Box2d for Cocos2d-X

Thursday, November 8th, 2012

I have been trying out LevelHelper recently and it has been very useful when making games that have a fair bit of physics.

I was looking at making a really simple game that did not require physics. Thats where LevelHelper seemed to fall over. Since the editor generates code for you and that code has reference to Box2D.

Fear not for all is not lost, you can still use LevelHelper without implementing the physics. You still need use the Cocos2D-X with Box2D template in xCode. You just don’t attach the physics properties.

So follow the tutorials on the LevelHelper site. When you get to the bellow line of code in the second video:

[cpp]
//attaches the physics properties and the sprites to the view.
loader->addObjectsToWorld(world, this);[/cpp]

The first parameter “world” is used to attach the physics properties. The second parameter “this” is what all the image assets in LevelHelper level are attached to. All you need to do is change the above line to:

[cpp]
//only attaches the sprites to the view.
loader->addObjectsToWorld(NULL, this);[/cpp]

Now just ignore any code to do with physics and Box2D.

2 comments on “Using LevelHelper without Box2d for Cocos2d-X

  1. Vladu Bogdan says:

    Cocos2d users already got a vanilla version (no box2d library required) – cocos2d-x will get this soon. At that time, you wont be needed box2d library included in your project. Until then, indeed this code works. Thanks for sharing to everybody!

Leave a Reply to abe Cancel reply

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