cocos2d 2.0自定义绘图导致不完整的场景渲染

时间:2013-02-12 11:47:51

标签: cocos2d-iphone

我有一个奇怪的问题,即使有大量的谷歌搜索和阅读,我还没有找到解决方案。

我有一个使用动态生成背景的场景。后台的代码基于这个tutorial和我发现的其他代码,例如Haqus Tiny-Wings github。

无论如何,我的代码简化了山丘生成,它全部包含在一个名为StripedTerrain的CCNode类中。这一切都很好(现在!)但是当去另一个使用相同布局和相同背景精灵的场景时,它不会完全渲染。请参阅screenshot。图像A是第一次使用我的代码运行。图像B是在对相同场景类的新场景的replaceScene调用之后。然后,在弹出矩阵之前,我对绘制代码做了一些小改动:

ccDrawColor4B(255, 255, 255, 255);
ccDrawLine(ccp(0.0,0.0),ccp(0.0,0.0));

然后它工作正常(图像C和D)

这是最奇怪的事情,我无法弄清楚出了什么问题。

我会发布绘制调用代码,但是除了剩下的详细信息之外的其他代码:

 /**
 * Previus to the draw method we have already done the following:
 * Randomly selected, or have been given two colors to paint the stripes onto our texture
 * Generated a texture to overlay on to our hill vertice geometry
 * Generated the top of the hill peaks and valleys
 * Generated the hill verticies that will fill in the surface of the hills
 * with the texture applied
 */
- (void) draw {

CC_NODE_DRAW_SETUP();
// this statement fixed the screwed up jagged line rendering
// since we are only using position and texcoord vertexes, we have to use this shader
kmGLPushMatrix();
CHECK_GL_ERROR_DEBUG();
ccGLBlendFunc( CC_BLEND_SRC, CC_BLEND_DST ); //TB 25-08-12: Allows change of blend function
ccGLBindTexture2D(self.stripes.texture.name);

//TB 25-08-12: Assign the vertices array to the 'position' attribute
glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, _hillVertices);

//TB 25-08-12: Assign the texCoords array to the 'TexCoords' attribute
glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, _hillTexCoords);
glEnableVertexAttribArray(kCCVertexAttrib_Position);
glEnableVertexAttribArray(kCCVertexAttrib_TexCoords);
//TB 25-08-12: Draw the above arrays
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)_nHillVertices);
CHECK_GL_ERROR_DEBUG();

//Debug Drawing (remove comments to enable)
if(0) {
    for(int i = MAX(_fromKeyPointI, 1); i <= _toKeyPointI; ++i) {
     ccDrawColor4B(255, 0, 0, 255);
     ccDrawLine(_hillKeyPoints[i-1], _hillKeyPoints[i]);
     }
    for(int i =0;i<_nHillVertices;i+=3) {
        ccDrawColor4B(255, 0, 0, 255);
        ccDrawLine(_hillVertices[i+1], _hillVertices[i+2]);
    }
}
// have to do this to force it to work the next scene load
ccDrawColor4B(255, 255, 255, 255);
ccDrawLine(ccp(0.0,0.0),ccp(0.0,0.0));
kmGLPopMatrix();
CC_INCREMENT_GL_DRAWS(1);


}

上面有任何明显的错误吗?

我已经在另一种方法中设置了着色器。

1 个答案:

答案 0 :(得分:0)

检查前一个场景及其子场是否运行dealloc方法。如果没有,并且一个或多个泄漏,最奇怪的事情就会发生。

在不调用超级清理的情况下,重写清理也是如此。