Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: Cocos2d: Can't create world with Box2D

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.

like image 578
FBryant87 Avatar asked Oct 13 '11 18:10

FBryant87


1 Answers

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.

like image 188
LearnCocos2D Avatar answered Oct 13 '22 18:10

LearnCocos2D