Game Development Reference
In-Depth Information
After adding the GB2ShapeCache files to your project, you'll notice that the project
won't compile without errors anymore. The problem is that GB2ShapeCache wasn't
written with ARC in mind. But that's easy to fix: simply go through the Edit Re-
factor Convert to Objective-C ARC . . . process again and allow Xcode to make the
necessary changes to the GB2ShapeCache files.
You should now drag and drop the PNG files located in the PhysicsBox2DPin-
ball01 project's Assets/pinball folder onto the leftmost pane in PhysicsEditor,
labeled Shapes.
Note You'll be using only the HD resolution images to create physics shapes
with PhysicsEditor. You don't have to create separate HD and SD resolution
physics shapes. The physics simulation world is independent from the graphical
representation of the objects and thus independent of the screen resolution.
The first thing you should modify in PhysicsEditor is the settings for the exporter.
PhysicsEditor can export to several game engines, supports both Box2D and Chipmunk
physics engines, and even allows you to create your own custom export format. To
write files compatible with cocos2d, you must set the Exporter setting on the rightmost
pane to Box2D generic (PLIST). Setting the exporter first is important because it en-
ables or disables some features of the PhysicsEditor GUI, depending on the targeted
physics engine's capabilities.
Next you should set the PTM-Ratio setting to 240. This value's unit is in pixels per
meter, meaning 240 pixels will equal 1 meter in the Box2D physics simulation world.
The dimensions of the Box2D physics world matter because Box2D is optimized to
work best with objects of 1 to 10 meters in size. You can easily run a simulation with
larger or smaller objects, but Box2D loses precision and can show odd behavior when
you have very large (tens or even hundreds of meters) or very small objects (small or
tiny fractions of a meter).
Because you're using high-resolution images in PhysicsEditor, the PTM-Ratio of 240
will create a pinball table that is 4 meters high (960 Retina-resolution pixels divided by
240) and 2.6 meters wide (640 Retina-resolution pixels divided by 240). The actual
pixels to meter ratio in cocos2d will be half the PTM-Ratio setting of PhysicsEdit-
or—in this case, 120 pixels per meter. This is because the cocos2d coordinate system is
in points, which means both the standard-resolution display and Retina displays have
Search Nedrilad ::

Custom Search