Game Development Reference
In-Depth Information
It's obvious that four edges don't suffice to model the outline for the image in Figure 4-7 .
You can add points by clicking anywhere on or near a line segment. Try to trace the im-
age's outline as seen in Figure 4-8 by adding more points and dragging them to their de-
sired position. It doesn't need to be perfect—far from it.
Figure 4-8 . The final version of the shape using as few points as possible to trace the image's outline
Note A line segment , or just segment , is a line with two defined end points.
Though commonly you would refer to it as a line as well, technically a line has
infinite length. A segment is a line between two points, having finite length. I'll
be using segment when I refer to the line between two points, but feel free to
read the word as “line” if you prefer.
For the best performance, try to minimize the number of polygon-shaped points. As a rule
of thumb, most shapes can be reasonably outlined with anywhere between 6 to 12 points.
Where more vertices are required, you should consider tracing the image outline more
roughly. Complex shapes are computationally more expensive as the number of polygon
points increases. Too-elaborate shapes can also introduce more or less subtle issues, like
objects getting stuck or bouncing off of each other in unrealistic ways.
If you need to delete a point on the shape, just right-click the point and it's gone. And if
you want to completely start over, deselect and reselect the “Enable physics” check box.
This will reset the polygon shape to a rectangle. However, this will also reset the body to
Dynamic as well as resetting all other physics properties to their default values; so use
this only as a last resort.
When editing polygon shapes, there are two things to watch out for: segments must never
cross, and segments must not be parallel or close to being parallel to each other.
SpriteBuilder will highlight invalid segments in red.
You can still publish and use shapes with invalid segments, but they will not behave cor-
rectly when it comes to collision detection and collision responses. Figure 4-9 shows an
example of two invalid segments: in the upper half two segments are intersecting (over-
Search WWH ::




Custom Search