Game Development Reference
In-Depth Information
Figure 4-13 . Screen shot from the game with physics debug drawing enabled
You may notice the polygons you've edited for the borders are actually made up of mul-
tiple smaller shapes. This is because internally the physics engine must work with convex
shapes, so SpriteBuilder splices the polygons up into as few convex shapes as possible in
order to represent non-convex (concave) polygons. In a time before SpriteBuilder, you ac-
tually had to ensure you didn't accidentally create concave shapes. What a pain that was!
Note Convex shapes are shapes where, put simply, a segment between any two
points on or inside the shape is always wholly contained inside the shape. For
example, circles, triangles, and rectangles are always convex, and so are
pentagons, hexagons, and similarly rounded shapes. A concave shape, on the
other hand, is a shape where at least one segment between any two points on or
inside the shape can be drawn so that it runs at least partially outside the shape's
area. For example, L-, T- and U-shaped areas are concave.
Try to create convex shapes for dynamic bodies whenever you can to improve
collision stability and performance. Decomposing a concave shape leaves tiny
“cracks” in the shape, which can sometimes cause dynamic bodies to respond to
collisions unexpectedly, like getting stuck for instance. Collision tests per-
formed against dynamic bodies with decomposed concave shapes are also com-
putationally more expensive.
The state of the project at this point can be found in the “04 - Physics Movement and
Level Borders” folder.
Search WWH ::




Custom Search