在我的项目下面使用了代码。它适用于iOS9-Cocos2d 2.0。现在在Cocos2d 2.2中,相同的代码无法正常工作...没有崩溃,但平台映像没有出现...如何为Cocos2d 2.2修复此问题?
-(CCSprite *)stripedSpriteWithColor1:(ccColor4F)c1 color2:(ccColor4F)c2 textureWidth:(float)textureWidth
textureHeight:(float)textureHeight stripes:(int)nStripes {
// 1: Create new CCRenderTexture
CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureWidth height:textureHeight];
// 2: Call CCRenderTexture:begin
[rt beginWithClear:c1.r g:c1.g b:c1.b a:c1.a];
// 3: Draw into the texture
// Layer 1: Stripes
CGPoint vertices[nStripes*6];
ccColor4F colors[nStripes*6];
int nVertices = 0;
float x1 = -textureHeight;
float x2;
float y1 = textureHeight;
float y2 = 0;
float dx = textureWidth / nStripes * 2;
float stripeWidth = dx/2;
for (int i=0; i<nStripes; i++) {
x2 = x1 + textureHeight;
vertices[nVertices] = CGPointMake(x1, y1);
colors[nVertices++] = (ccColor4F){c2.r, c2.g, c2.b, c2.a};
vertices[nVertices] = CGPointMake(x1+stripeWidth, y1);
colors[nVertices++] = (ccColor4F){c2.r, c2.g, c2.b, c2.a};
vertices[nVertices] = CGPointMake(x2, y2);
colors[nVertices++] = (ccColor4F){c2.r, c2.g, c2.b, c2.a};
vertices[nVertices] = vertices[nVertices-2];
colors[nVertices++] = (ccColor4F){c2.r, c2.g, c2.b, c2.a};
vertices[nVertices] = vertices[nVertices-2];
colors[nVertices++] = (ccColor4F){c2.r, c2.g, c2.b, c2.a};
vertices[nVertices] = CGPointMake(x2+stripeWidth, y2);
colors[nVertices++] = (ccColor4F){c2.r, c2.g, c2.b, c2.a};
x1 += dx;
}
self.shaderProgram =
[[CCShaderCache sharedShaderCache] programForKey:kCCShader_PositionColor];
CCSprite *noise;
noise = [CCSprite spriteWithFile:@"FarmBase.png"];
[noise setBlendFunc:(ccBlendFunc){GL_DST_COLOR, GL_ZERO}];
noise.position = ccp(textureWidth/2, textureHeight/2);
[noise visit];
[rt end];
// 5: Create a new Sprite from the texture
return [CCSprite spriteWithTexture:rt.sprite.texture];
}