Game Development Reference
In-Depth Information
The Box2D physics engine, written in C++, was developed by Erin Catto, who has giv-
en presentations about physics simulations at every Game Developers Conference
(GDC) since 2005. It was his GDC 2006 presentation that eventually led to the public
release of Box2D in September 2007. It's been in active development ever since.
Because of its popularity, the Box2D physics engine is distributed with cocos2d. You
can create a new project using Box2D by choosing the cocos2d Box2D application
template from Xcode's File New Project dialog. This project template adds the ne-
cessary Box2D source files to the project and provides a test project in which you can
add boxes that bounce off each other, as shown in Figure 12-1 . The boxes also fall ac-
cording to gravity, depending on how you're holding your device.
Figure 12-1 . The PhysicsBox2D example project
Caution Because the Box2D physics engine is written in C++, you have to use
the file extension .mm instead of .m for all your project's implementation files.
This tells Xcode to treat the implementation file's source code as either
Objective-C++ or C++ code. With the .m file extension, Xcode will compile
the code as Objective-C and C code and won't understand Box2D's C++ code,
which will result in numerous compile errors for every line of code that uses or
makes a reference to Box2D. So if you're getting a lot of errors related to
Box2D, check that your implementation files all end in .mm , and if not, rename
them.
 
 
Search Nedrilad ::




Custom Search