I posted in another topic yesterday about issues with actions and I appreciate the help I recieved! I have moved further along. I know how to do a delay with a callout now!, but I think I have gotten myself in a bind with layers and sprites and nodes (oh my!). I have a slideshow that has a foreground and a background and Im trying to seamlessly blend from one to the other over time. The slideshow automatically repeats and has a nice little music track with it..... But...(there is always a butt, isnt there?)
Depending on one line of code, the behavior changes dramatically. Ive been looking at this for hours and i'm not wrapping my noobie brain around it....
Here is the code in question.
-(void)displaySlide: (int)slideNumber {
/*
* Remove existing slide and description.
*/
if ([self background]) {
id action_bg = [FadeOut actionWithDuration:5.0f];
[background runAction:action_bg];
//[self removeChild:[self background] cleanup:YES];
}
/*
* Retrieve and generate necessary details for next slide.
*/
NSString * bgString = [[self backgrounds] objectAtIndex:slideNumber];
Sprite * bg = [Sprite spriteWithFile:bgString];
id action1= [Sequence actions: [FadeIn actionWithDuration:5.0],[DelayTime actionWithDuration:5.0f],nil];
id action2 = [ScaleBy actionWithDuration:10.0 scaleX:1.2 scaleY:1.2];
id actionStop =[Sequence actions:
[DelayTime actionWithDuration:10.0f],
[CallFunc actionWithTarget:self selector:@selector(removeSprite)], nil];
bg.opacity = 0.0f;
bg.position = ccp([self backgroundXPosition], [self backgroundYPosition]);
// Run the following actions in Parallel
[bg runAction:action1];
[bg runAction:action2];
//[background runAction:actionStop];
// Add the background and desc to the layer.
[self setBackground:bg];
[self addChild:bg];
}
and some accompanying methods...
-(void)removeSprite {
if(background) [self removeChild:[self background] cleanup:NO];
}
-(void)setBackground: (Sprite *)aSprite {
if (background) [background release];
background = [aSprite retain];
}
If the code runs AS-IS, the slideshow will do the fade-out / fade-in transitions perfectly between the two sprites, BUT as the slide show progresses, it gets slower and slower from 60 FPS down to 5FPS and my retained allocations goes as high as 50MB before I stopped it.
if I uncomment one line -
//[self removeChild:[self background] cleanup:YES];
up at the beginning, the background child node gets deleted early on and the slideshow runs @ 60FPS for its duration. I have experimented with moving this line to many places within the program, including making it the subject of "removeSprite" (where it is pictured currently). My thinking was to remove this node only once the background sprite had finished its transition, but I'm getting twisted in the logic somehow.
Thanks in advance!