Game Development Reference
In-Depth Information
The freeAllocatedMemory method called by dealloc takes care of releasing the
memory allocated to these pointers by calling free on them. The variables are also set to
nil simply because it's good style never to leave a pointer dangling. (A dangling pointer
is a pointer that points to a deallocated block of memory.) Since both _vertices and
_initialBodyPositions will be allocated manually using the C programming lan-
guage's standard library functions ( malloc , calloc , realloc ), their memory must
also be deallocated manually using the free function.
Caution ARC frees you only from manually managing the memory of
Objective-C class instances, but not memory allocated with C functions or the
C language variant and the predecessor of Cocoa, named Core Foundation.
CCVertex is a struct type exposed by the Cocos2D rendering API. See Listing 10-9
for reference, with the fields shown in brackets.
Listing 10-9 . The CCVertex type defines the vertex position, two texture coordinates,and a
color property
typedef struct CCVertex {
GLKVector4 position; // position (x, y, z, w)
GLKVector2 texCoord1, texCoord2; // texture
coordinates (x, y)
GLKVector4 color; // color (r, g, b, a)
} CCVertex;
The GLKVector2 and GLKVector4 types are defined by Apple's GLKit and are also
struct s containing two four-float (not CGFloat ) values. The position, unlike most
low-level OpenGL commands, is in points. That's one benefit of the new Cocos2D ren-
dering API—you no longer have to consider point-to-pixel conversion when writing ren-
dering code. Of the two texture-coordinate fields, only texCoord1 is used in this ex-
ample. It defines the coordinate within the texture that maps to this vertex. Texture co-
ordinates are expressed as a percentage of the texture's size in the range 0.0 to 1.0. Fin-
ally, the colors are RGB values with an alpha value, also in the range of 0.0 to 1.0.
The _enlargeTextureRadius ivar will be used to increase the radius for the texture
coordinates. This ensures that the player image isn't cut off. The _enlargeDrawRadi-
Search WWH ::




Custom Search