0

我有一个奇怪的问题,尽管进行了大量的谷歌搜索和阅读,但我还没有找到解决方案。

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

无论如何,我的代码已经简化了山的生成,它都包含在一个名为 StripedTerrain 的 CCNode 类中。一切正常(现在!),但是当转到另一个使用相同布局和相同背景精灵的场景时,它不会完全渲染。见截图。图像 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);


}

上面有什么明显的错误吗?

我用另一种方法设置了着色器。

4

1 回答 1

0

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

在不调用超级清理的情况下覆盖清理也是如此。

于 2013-02-12T13:58:22.247 回答