Game Development Reference
In-Depth Information
@private
int _numVertices;
CCVertex* _vertices;
CGPoint* _initialBodyPositions;
CGFloat _enlargeTextureRadius;
CGFloat _enlargeDrawRadius;
}
-(void) dealloc
{
[self freeAllocatedMemory];
}
-(void) freeAllocatedMemory
{
free(_vertices);
_vertices = nil;
free(_initialBodyPositions);
_initialBodyPositions = nil;
}
-(void) didLoadFromCCB
{
[self setup];
}
@end
For the drawing code, you'll make use of the allocated memory buffer. This is classic C-
programming memory management. Since CGPoint and CCVertex are struct data
types, they cannot be added to regular Cocoa collection classes like NSArray without
wrapping (boxing) them first with NSValue objects. Since wrapping and unwrapping
creates unnecessary overhead, something you'll want to avoid in tight render loops, and
since C-style memory buffers really aren't that complex, they are arguably the best choice.
In this case, _vertices and _initialBodyPositions are pointers to a block of
memory that will be allocated to hold exactly _numVertices CCVertex and
CGPoint types. The vertices are used to draw the texture, while _initialBodyPos-
itions gives you access to the positions of the bodies as they were designed in
SpriteBuilder. They are needed to compute the texture coordinates from the nondeformed
player, but theoretically you could also use them to determine the degree of deformation
(the deviation from its original position) each body is currently experiencing.
Search WWH ::




Custom Search