Game Development Reference
You first create a UIWindow and then decide on a CCDirector type to use and set
the animation interval to 60 frames per second. This is the default behavior.
The EAGLView line is important because for overlapping tiles to render properly, you
have to specify a depth buffer with the depthFormat parameter. In this case, it's
GL_DEPTH_COMPONENT24_OES , which creates a depth buffer of 24 bits. To con-
serve memory, you can also use a 16-bit depth buffer, which may be sufficient.
Depth buffering allows OpenGL to determine whether a certain pixel is in front or be-
hind another pixel so it can decide whether to actually draw the new pixel or discard it.
This comes at a cost of additional memory usage—nearly 2 MB for a 24-bit depth buf-
fer on Retina devices—but it allows sprites and tiles to correctly overlap one another.
The other really important line in the initialization is setProjection , which puts
cocos2d in 2D projection mode. This changes a couple of OpenGL parameters that af-
fect the way cocos2d renders nodes. In this case, it fixes the issue in Figure 11-12
where the ground floor is not rendered as expected, with the final result shown in Fig-
vertexZ property rather than the zOrder property of sprites.
By default, cocos2d's z-ordering of nodes is based on the z value when you're adding a
node via the addChild method. Nodes with a lower z-order are drawn before nodes
with a higher z-order. Nodes that have the same z-order are drawn in the order in which
they've been added to the node hierarchy, meaning nodes added last will be drawn over