Game Development Reference
In-Depth Information
i++;
}
}
[self updateTextureCoordinates];
}
The setup method first calls freeAllocatedMemory . This is just in case the meth-
od runs more than once. If the previously allocated memory isn't freed, it will be lost
(leaked), because the memory will still be allocated but you won't have any access to it
anymore. This is because the setup method allocates new chunks of memory and as-
signs the pointers to the _vertices and _initialBodyPositions .
The _numVertices ivar is set to the number of child nodes plus one. With nine child
nodes (one center plus eight circumference nodes), that makes 10 vertices. Why 10? The
tenth vertex is the one that closes the loop. The center vertex is the first, then comes the
right one, then the other ones, up to the top-right vertex. And that's where you need to du-
plicate the right vertex once more so that the triangle formed by the vertices center (1),
top-right (9), and right (2) can be drawn. See Figure 10-5 for visual clarification.
Figure 10-5 . This triangle fan (with vertex numbers) is used to draw the textured soft-body player
Essentially, the soft-body circle must be divided into triangles to be drawable by the Co-
cos2D renderer. The first triangle is 1-2-3, and subsequent triangles can be added by
Search WWH ::




Custom Search