Game Development Reference
In-Depth Information
transform);
CCRenderBufferSetVertex(buffer, lastIndex, v);
for (int i = 0; i < numTriangles; i++)
{
CCRenderBufferSetTriangle(buffer, i, 0, i+1, i+2);
}
}
First, the number of triangles is determined. Since the first three vertices form one triangle
and each subsequent triangle forms another triangle in a triangle fan, the number of tri-
angles is the number of vertices minus two. The CCRenderer object is then queried for
a CCRenderBuffer struct type. The buffer is allocated by CCRenderer to hold
the given number of triangles and vertices.
The render state to draw textured triangles is already set up for you by the CCSprite
base class, so you can simply pass in self.renderState . The render state is simply
the combination of the blend mode, shader, and texture. Already and implicitly set up by
CCSprite are the blend mode and shader program, whereas the texture is assigned by
CCBReader via the spriteFrame property. In case you want to know, the default
blend mode and shader for a CCSprite are set as follows:
self.blendMode = [CCBlendMode premultipliedAlphaMode];
self.shader = [CCShader positionTextureColorShader];
Tip If you want to do custom drawing with textures, it'll be easiest to do so in
a CCSprite subclass. Otherwise, you'll have to create a CCRenderState
object yourself in order to pass the blend mode, shader program and a (optional)
texture to CCRenderer . You may also want to make use of the CCRender-
CheckVisibility method that prevents anything from being drawn outside
the region defined by this method. It's not used in this example because the
player is always visible. And if you have to or want to use OpenGL commands
directly, you should do so by writing the code in a block or method enqueued
by CCRenderer 's enqueueBlock: or enqueueMethod: method. By-
passing CCRenderer for custom drawing code may lead to unexpected side
effects, and you won't benefit from Cocos2D's new Metal renderer (not to be
confused with Nu Metal).
Search WWH ::




Custom Search