Game Development Reference
In-Depth Information
Lastly you should save the current PhysicsEditor .pes file. You can later open the
.pes file to continue editing shapes. You shouldn't add the .pes file to your Xcode
project; it's used only by PhysicsEditor.
To use the shapes in cocos2d, you use the Publish button. This creates a .plist file
that the GB2ShapeCache class distributed with PhysicsEditor can read. For the
PhysicsBox2DPinball01 project, I published the shapes as pinball-
shapes.plist in the Resources folder of the project. Add this file to the Re-
sources group in Xcode.
Programming the Pinball Game
Now you can move on to the implementation phase and actually program the pinball
game. You'll learn how to lay out the table before moving on to the interactive ele-
ments like the ball, plunger, bumpers, and flippers. But before we get to that, I'd like to
introduce you to the essential BodySprite class, which synchronizes a cocos2d
sprite with a Box2D body not unlike the PhysicsSprite class provided by
cocos2d's Box2D project template. The main difference is that BodySprite uses the
GB2ShapeCache class to create its b2Body object and will also destroy its body
when a BodySprite object is released from memory.
Caution Keep in mind that the pinball project uses Box2D, which is written in
C++. This requires you to use the .mm file extension instead of .m for all class
implementation files so that the compiler correctly switches to compiling C++
code instead of C code. Whenever you create a new Objective-C class, you
have to rename the implementation file so that it uses the .mm file extension.
Otherwise, you'll see a lot of compile errors seemingly caused by the Box2D
source code.
Forcing Portrait Orientation
The pinball table is designed to be played in portrait orientation, but cocos2d sets up its
project templates to use only landscape orientation. You can easily fix that by opening
Search Nedrilad ::

Custom Search