Export to GitHub

cocos2d-iphone - issue #1516

CCRenderTexture image change gradually


Posted on Apr 6, 2014 by Massive Horse

What steps will reproduce the problem? 1.CCRenderTexture

What is the expected output? What do you see instead?

What cocos2d version are you using ? 2.0

What iOS / Mac SDK are you using ? iOS 7.1 and iOS 6

Debug or Release ? Debug

Which target device / target OS are you using ? iphone 5s, iphone4, and iphone emulators

iOS only: Does this happens on device ? or on the simulator ? or on both ? both

Mac only: x86 or i386 ?

Please provide any additional information below.

here is the code:

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

CCSprite *noise= [CCSprite spriteWithFile:@"Noise.jpg"];

[noise visit];


CC_NODE_DRAW_SETUP();



nVertices = 0;

vertices[nVertices] = CGPointMake(0, 0);
colors[nVertices++] = (ccColor4F){0, 0, 0, 0};

vertices[nVertices] = CGPointMake(textureWidth, 0);
colors[nVertices++] = (ccColor4F){0, 0, 0, 0};

vertices[nVertices] = CGPointMake(0, textureHeight);
colors[nVertices++] = (ccColor4F){0, 0, 0, gradientAlpha};

vertices[nVertices] = CGPointMake(textureWidth, textureHeight);
colors[nVertices++] = (ccColor4F){0, 0, 0, gradientAlpha};

glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_TRUE, 0, colors);
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);*/
//glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);

// layer 3: top highlight
float borderHeight = textureHeight/16;
float borderAlpha = 0.6f;
nVertices = 0;

vertices[nVertices] = CGPointMake(0, 0);
colors[nVertices++] = (ccColor4F){0, 0.4, 0.2, borderAlpha};

vertices[nVertices] = CGPointMake(textureWidth, 0);
colors[nVertices++] = (ccColor4F){0, 0.4, 0.2, borderAlpha};

vertices[nVertices] = CGPointMake(0, borderHeight);
colors[nVertices++] = (ccColor4F){0, 0.4, 0.2, 0};

vertices[nVertices] = CGPointMake(textureWidth, borderHeight);
colors[nVertices++] = (ccColor4F){0, 0.4, 0.2, 0};

glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_TRUE, 0, colors);
glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);

// 4: Call CCRenderTexture:end
[rt end];

// 5: Create a new Sprite from the texture
return [CCSprite spriteWithTexture:rt.sprite.texture];

}

and here is the call

CCSprite *stripes = [self stripedSpriteWithColor1:color3 color2:color4 textureWidth:IS_IPHONE_5 ? 512:256 textureHeight:256 stripes:4]; ccTexParams tp2 = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_CLAMP_TO_EDGE}; [stripes.texture setTexParameters:&tp2];

Attachments

Comment #1

Posted on Apr 6, 2014 by Massive Horse

the problem seems not present on the emulators.

Comment #2

Posted on Apr 8, 2014 by Helpful Monkey

pls help me i really need to solve this...

Comment #3

Posted on Apr 9, 2014 by Helpful Monkey

the game is like tiny wings so the world is moving constantly and so the background.

Status: New

Labels:
Type-Defect Priority-Medium