Okay, I have a Sprite which has 2 animations.
The first begins at initialization and is a repeat-forever action. This is because I want it to repeat for as long as it needs to (until it is clicked)
When it is clicked I want it to switch to a different animation (which explodes the star) and then have it disappear.
I've had it close a few times but can never get it to work right.
The way I have it now, the second animation runs (showing the star exploding), but then the RepeatForever animation comes back.
I tried stopping the first animation a few different ways but can't figure it out.
Here is pretty much the entire code for the file. clicked is called when the star is clicked from the base layer.
//init with x and y coordinates of where to put star
-(id) init :(int) ix sety:(int) iy
{
//super init with first twinkle file
self = [super initWithFile:@"Explode0013.png"];
if (self != nil) {
frameCount = 0;
[self setPosition:ccp(ix , iy)];
self.autoCenterFrames = YES;
//initialize anitmation
starTwinkle = [[Animation alloc] initWithName:@"starTwinkle" delay:0.2];
for(int i = 1; i <= 5; i++){
[starTwinkle addFrameWithFilename:[NSString stringWithFormat:@"startwinkle%d.png", i]];
}
id twinkleAnim = [RepeatForever actionWithAction:[Animate actionWithAnimation:starTwinkle]];
[self runAction:twinkleAnim];
}
return self;
}
-(void) clicked{
/*[self stopAllActions];
int newx = [self position].x;
int newy = [self position].y;
self = [self initWithFile:@"Explode0001.png"];
x = newx;
y = newy;
[self setPosition:ccp(x,y)];
self.autoCenterFrames = YES;*/
starExplode = [[Animation alloc] initWithName:@"starExplode" delay:.2];
for(int i = 1; i <= 13; i++){
[starExplode addFrameWithFilename:[NSString stringWithFormat:@"Explode%04d.png", i]];
}
id explodeAnim = [Animate actionWithAnimation:starExplode];
[self runAction:explodeAnim];
}