Game Development Reference
In-Depth Information
simply adding one more vertex each. After 1-2-3, the next triangle is 1-3-4 followed by
1-4-5 and so on. This is called a triangle fan , which is a drawing mode where each subse-
quent vertex is assumed to form another triangle with the originating vertex and the last
vertex.
In Listing 10-10 , both _vertices and _initialBodyPositions are allocated.
The amount of memory allocated is _numVertices multiplied by the size of the corres-
ponding type. For instance, _vertices will allocate 10 * 48 bytes of memory, a total
of 480 bytes. So it's really not much, especially in relation to the sprite's texture memory.
Both pointers point to an allocated chunk of memory, and both can be accessed like an
Objective-C array using the same subscripting operator as in C. See, for instance, the as-
signment in the last line in Listing 10-11 .
Tip Texture memory size is a multiple of the texture size times color depth.
The file size of the corresponding image will typically be far smaller. A com-
mon beginner's mistake is to assume texture memory usage is identical to the
image file size. Alas, texture memory (for uncompressed formats) can be calcu-
lated with the following pseudo-code: pixelWidth * pixelHeight *
(colorBitDepth / 8) . For instance, a 4096x4096 image with 32-bit col-
ors will use this much memory as an uncompressed texture: 4096 * 4096 *
(32 / 8) = 67,108,864 bytes (equals 64 megabytes).
The center node's position is needed as a reference (origin) point and is stored in the
centerPos variable. You need it for the calculation inside the for loop, which enumer-
ates over all child nodes. The first node is the center node. Its position is assigned to
_initialBodyPositions as is. The remaining points are updated to enlarge the ra-
dius of the circle by the value specified in the _enlargeTextureRadius ivar. Listing
10-11 reprints this part of the loop.
Listing 10-11 . Assuming the initial body positions to be on a larger circle
CGPoint centerToChild = ccpSub(child.positionInPoints,
centerPos);
CGFloat newRadius = ccpLength(centerToChild)
+ _enlargeTextureRadius;
CGPoint newPos = ccpMult(ccpNormalize(centerToChild),
newRadius);
_initialBodyPositions[i] = ccpAdd(newPos, centerPos);
Search WWH ::




Custom Search