I can run CCWave actions on sprites with no problem, except for this particular instance. I initialize a class of mine that has a CCSprite that I add to a CCRenderTexture. The sprite is made by adding tile sprite textures to a CCRenderTexture, and then removing the tiles. I can add the sprite to the CCRenderTexture as a child with no problem, but if I add the CCWave function and run it, the sprite disappears.
// 1: Create new CCRenderTexture
CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:width height:height];
// 2: Call CCRenderTexture:begin
[rt beginWithClear:0 g:0 b:0 a:0];
/* this is a loop where I get all tiles
within a bounding object's rectangle */
CGPoint tileCoord;
for(int w = 0; w < (width / tilePxWidth); ++w){
for(int h = (height / tilePxWidth); h > 0; --h){
tileCoord = [TileCoord tileCoordForPosition:ccp(x + (w * tilePxWidth),
y + (h * tilePxWidth))
withMap:theMap];
CCSprite *backgroundTileSprite = [self.background tileAt:tileCoord];
CCSprite *copiedSprite = [CCSprite spriteWithTexture:backgroundTileSprite.texture
rect:backgroundTileSprite.textureRect];
[copiedSprite.texture setAliasTexParameters];
copiedSprite.position = ccp(8 + (w * tilePxWidth),
(8 + (h * tilePxWidth)) - 16);
// 3: Visit to update renderTexture (rt)
[copiedSprite visit];
[self.background removeTileAt:tileCoord];
}
}
// 4: Call CCRenderTexture:end
[rt end];
// 5: Create a new sprite from the texture
waterLine.tilesSprite = [CCSprite spriteWithTexture:rt.sprite.texture];
[theMap addChild:waterLine.tilesSprite z:[[theMap layerNamed:@"background"] zOrder]-1];
waterLine.tilesSprite.flipY = YES;
waterLine.tilesSprite.anchorPoint = CGPointZero;
waterLine.tilesSprite.position = ccp(x,y);
[waterLines insertObject:waterLine atIndex:waterLineNum];
// if I add the code below, the sprite no longer shows up!
id waveEffect = [CCWaves actionWithDuration:25
size:CGSizeMake(1,10)
waves:3
amplitude:8
horizontal:NO
vertical:YES];
[waterLine.tilesSprite runAction:[CCRepeatForever actionWithAction:waveEffect]];
Just a few extra details you might be curious about. I have a transparent background in this game so the background can run separately from the game when I do scene transitions.
Some stuff in my delegate:
CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:GL_DEPTH24_STENCIL8_OES
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
glView.opaque = NO;
glClearColor(0.0f,0.0f,0.0f,0.0f);
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
I just realized it seems this effect has to be done on a spriteSheet, not a sprite.