I have some sprites of stars twinkling and the images are too big to fit on one sprite sheet, so I have had to spread them across two. I have been looking for how to create a single animation using the images from both sprite sheets, but have had no luck.
This is what I tried, it complies ok but then crashes when the animation gets to where the images start coming from the second sprite sheet.
//=======================================================================================//
//Load Stars
frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"starsOne_01.plist"];
[frameCache addSpriteFramesWithFile:@"starsOne_02.plist"];
starSpriteNodeOne_01 = [CCSpriteBatchNode batchNodeWithFile:@"starsOne_01.png"];
[self addChild:starSpriteNodeOne_01 z:-2];
starSpriteNodeOne_02 = [CCSpriteBatchNode batchNodeWithFile:@"starsOne_02.png"];
[self addChild:starSpriteNodeOne_02 z:-2];
//Load frames
starOneFrames_01 = [NSMutableArray array];
for(int i = 1; i <= 12; ++i) {
[starOneFrames_01 addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"starsOne_%d.png", i]]];
}
starOneAnim_01 = [CCAnimation animationWithFrames:starOneAnim_01 delay:0.5f];
[[CCAnimationCache sharedAnimationCache] addAnimation:starOneAnim_01 name:@"starOneAnim_01"];
//=======================================================================================//
//Add stars to the scene
starsOne = [CCSprite spriteWithSpriteFrameName:@"starsOne_1.png"];
starsOne.anchorPoint = ccp(0, 0.5);
starsOne.position = ccp(0, size.height/2);
[starSpriteNodeOne_01 addChild:starsOne];
//animate
starOneAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:starOneAnim_01 restoreOriginalFrame:YES]];
[starsOne runAction:starOneAction];
Any ideas where I am going wrong? Thanks in advance.
Hi @JorisMans, I tried your method and it seems to work up till the point where it tries to add the animation to the second sequence. I have tried running the methods in reverse order(so starAnimation_02 first) and it still gives the same out come. The first method runs normally then when the second method to be called runs it crashes. Here are my two methods, I have kept the CCLOG in one of them so you understand where it crashes. The program reaches the REACHED3 CCLOG before crashing.
-(void)starAnimation_01
{
[starsOne_01 setVisible:YES];
[starsOne_02 setVisible:NO];
CCCallFunc* customCall = [CCCallFunc actionWithTarget:self selector:@selector(starAnimation_02)];
CCSequence* actionSeq = [CCSequence actions:[CCAnimate actionWithAnimation:starOneAnim_01 restoreOriginalFrame:NO],customCall,nil];
[starsOne_01 runAction:actionSeq];
}
-(void)starAnimation_02
{
[starsOne_02 setVisible:YES];
CCLOG(@"===================REACHED========================");
[starsOne_01 setVisible:NO];
CCLOG(@"===================REACHED2========================");
CCCallFunc* customCall2 = [CCCallFunc actionWithTarget:self selector:@selector(starAnimation_01)];
CCLOG(@"===================REACHED3========================");
CCSequence* actionSeq2 = [CCSequence actions:[CCAnimate actionWithAnimation:starOneAnim_02 restoreOriginalFrame:NO],customCall2,nil];
CCLOG(@"===================REACHED4========================");
[starsOne_02 runAction:actionSeq2];
}