It’s pretty simple really but here is a quick how-to. This is based on XCode 4.
- In a finder window, go into your Cocos2D-X folder and you’ll see the Box2D folder in there.
- Drag the folder into your project, the adding files dialog will show, leave the defaults st and click the Finish button to add it all.
- In your project expand your new Box2D folder.
- All you want in the Box2D folder is the file “Box2D.h” and three folders “Collision”, “Common” and “Dynamics”, so remove the others by highlighting and pres DEL – select the “remove references only” button.
- Again in the project view, click your project file at the top to show the build settings for your project.
- Scroll down the list to the “Header Search Paths” item. Edit the search paths and add the following to the end (including the quote marks, just copy and paste this whole string):
“$(SRCROOT)/../” “$(SRCROOT)/../../” “$(SRCROOT)/../../box2d”
Build it, it should compile fully.
Box2D Debug Draw “SetDebugDraw” and “GLES-Render”
Now you can stop there but three is also “GLES-Render” class which is useful for debugging your Box2D – with the class you can have Box2D draw the vectors (the collision areas) of the Box2D objects in your scene. Useful if say something is colliding where it shouldn’t and you can see the actual collision area of the object.
You will find the “GLES-Render.cpp” and “GLES-Render.h” files in the “cocos2D-xxxxx/Tests/Tests/Box2DTestBed” folder. Copy them into your projects folder and add them to your project.
The post Cocos2D-X: Adding Box2D to your Project appeared first on GMT Dev Blog.