8

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
FBryant87
  • 4,273
  • 2
  • 44
  • 72
  • 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. – CodeSmile Oct 13 '11 at 19:14

1 Answers1

25

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Thank you Steffen. It seems Box2D official reference misses the update. http://box2d.org/manual.pdf page 8 still has the old way of creating the world. BTW, you have set a very nice "listener port" for Cocos2D questions :). – Mikayil Abdullayev Feb 10 '13 at 19:16