Sunday, July 29, 2012

Adding Box2D Files to your Cocos2D Project


  1. First, download 'cocos2d-iphone-x.0.tar.gz' , and Open a Finder window and navigate to where you downloaded the Cocos2D source.
  2. Open the folder and navigate to external\Box2d\Box2D. 
  3. Open a second Finder window, navigate to your project, and navi-
    gate to libs. 
  4. Copy the Box2D folder to the libs folder. 








  • Adding the Box2D directory to your Xcode project   


  • You have to set "User Header Search Paths" as 'Project_Name/libs'



  • And also you have to add two more files :
    the ones responsible for drawing Box2D objects to the screen for debug purposes.


  navigate to your Cocos2D directory, and navigate to templates\cocos2d_box2d_app\Classes. Inside you’ll find the files GLES- Render.h and GLES-Render.mm. Select those two files and drag them to your new Box2D group in Xcode. Make sure Copy items into destination group’s folder (if needed) is checked, and click Finish.

  • After that  #import "Box2D.h", what ever file you want and mack sure rename the file with a '.mm' extension. Because you are importing the Box2D header file (which uses C++) in files that are set up to use only Objective-C. To instruct the compiler to allow both C++ and Objective-C, we can add '.mm' extension.