2013-02-12 38 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