8
votes

My project originated as the cocos2d Box2D template and I'm having issues as soon as I tried to create a world:

world = new b2World(gravity,doSleep);

Gives the error: No matching constructor for initialization of 'b2World'.

The file is .mm, I assume it's some issue about library linking maybe? If so I'm using xCode 4, how can I check the lib is properly linked?

Thanks.

1
Which cocos2d version are you using? If it's cocos2d 2.0 alpha then that should come with an updated "cocos2d with box2d" project template. - LearnCocos2D

1 Answers

25
votes

You are using Box2D v2.2 or newer. The b2World constructor no longer takes two arguments, just one (gravity). You have to set doSleep separately:

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

This won't be the only change you'll need to make to transition from Box2D v2.1.x to v2.2.x. Kobold2D has a working Box2D 2.2.1 sample project, even if you don't use Kobold2D you can get updated source code for Box2D basics. In particular the GLESDebugDraw class and how to setup a screen bounding box with a body using multiple shapes.