2013-02-12 34 views
0

我有一个奇怪的问题,我还没有找到一个解决方案,尽管很多和大量的谷歌搜索和阅读。cocos2d 2.0自定义绘图导致不完整的场景呈现

我有一个使用动态生成背景的场景。背景代码基于这个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); 


} 

任何明显的失误上面?

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

回答

0

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

重写清理同样可以不调用超级清理。

+0

不,我做了所有这些明显的事情。 – Mark 2013-02-12 19:21:48

+0

我会内联ccDrawLine的所有内容,看看你有多少注释可以再次出现。可能与ccGLEnableVertexAttribs有关?如果标志被设置,那将启用kCCVertexAttrib_Color。 – Pat 2013-02-16 01:11:01