Cocos2d iphone cocos2d 2.0自定义图形导致场景渲染不完整

Cocos2d iphone cocos2d 2.0自定义图形导致场景渲染不完整,cocos2d-iphone,Cocos2d Iphone,我有一个奇怪的问题,我没有找到一个解决办法,尽管有很多谷歌搜索和阅读 我有一个使用动态生成背景的场景。背景代码基于此以及我发现的与之相关的其他代码,如Haqus Tiny Wings github 无论如何,我的代码简化了hill生成,它都包含在一个名为StripedTerrain的CCNode类中。这一切都很好(现在!),但当转到另一个使用相同布局和相同背景精灵的场景时,它不会完全渲染。看。图A是我的代码第一次按原样运行。图像B是在对同一场景类的新场景调用replaceSecene后生成的。然

我有一个奇怪的问题,我没有找到一个解决办法,尽管有很多谷歌搜索和阅读

我有一个使用动态生成背景的场景。背景代码基于此以及我发现的与之相关的其他代码,如Haqus Tiny Wings github

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

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);


}
/**
*对于draw方法,我们已经做了以下工作:
*随机选择,或已被赋予两种颜色,以在纹理上绘制条纹
*生成纹理以覆盖到我们的hill vertice几何体
*产生了山顶的山峰和山谷
*生成将填充山丘表面的山丘垂直
*应用纹理后
*/
-(作废)提款{
CC_节点_绘图_设置();
//此语句修复了扭曲的锯齿线渲染
//因为我们只使用位置和texcoord顶点,所以必须使用此着色器
KMGL矩阵();
检查_GL_ERROR_DEBUG();
ccGLBlendFunc(CC_BLEND_SRC,CC_BLEND_DST);//TB 25-08-12:允许更改混合函数
ccGLBindTexture2D(self.stripes.texture.name);
//TB 25-08-12:将顶点数组指定给“位置”属性
glVertexAttributePointer(kCCVertexAttrib_位置,2,GL_浮动,GL_假,0,_hillVertices);
//TB 25-08-12:将texCoords数组分配给“texCoords”属性
glvertexattributepointer(kCCVertexAttrib\u TexCoords,2,GL\u FLOAT,GL\u FALSE,0,\u hillTexCoords);
glEnableVertexAttribArray(KCcVertexAttribU位置);
glEnableVertexAttribArray(kCCVertexAttrib_TexCoords);
//TB 25-08-12:绘制上述阵列
glDrawArray(GL\u三角形\u带,0,(GLsizei)\u顶点);
检查_GL_ERROR_DEBUG();
//调试图形(删除注释以启用)
如果(0){

对于(int i=MAX(_fromKeyPointI,1);i检查前一个场景及其子场景是否运行了dealloc方法。如果没有,则一个或多个正在泄漏,可能会发生最奇怪的事情


覆盖清理而不调用超级清理也是如此。

不,我做了所有明显的事情,比如说。我会将所有ccDrawLine内联,看看在它再次中断之前你可以注释多少。可能与ccGLEnableVertexAttribs有关?如果设置了标志,这将启用kCCVertexAttrib\u颜色。