Xcode: Cocos2d: Unable to create a world with Box2D

My project came about as a cocos2d Box2D template, and I had problems as soon as I tried to create a world:

world = new b2World(gravity,doSleep); 

Gives an error: there is no matching constructor to initialize 'b2World'.

The .mm file, I assume this could be a library problem? If so, I am using xCode 4, how can I verify that lib is properly connected?

Thanks.

+8
objective-c xcode cocos2d-iphone box2d
source share
1 answer

You are using Box2D v2.2 or later. The b2World constructor no longer accepts two arguments, only one (gravity). You must install doSleep separately:

 world = new b2World(gravity); world->SetAllowSleeping(doSleep); 

This will not be the only change you will need to make to upgrade from Box2D v2.1.x to v2.2.x. Kobold2D has a working example of Box2D 2.2.1, even if you are not using Kobold2D, you can get updated source code for the basics of Box2D. In particular, the GLESDebugDraw class and how to set up a body screen bounding screen using several forms.

+25
source share

All Articles