so I’m creating a sprite every second but now I would like to replace this sprite by a spriteSheetAnimation. but when I run this code my app crashes :
- (void)spawnCat {
CCSpriteBatchNode *spriteSheet2 = [CCSpriteBatchNode batchNodeWithFile:@"AnimBulle.png"];
[self addChild:spriteSheet2];
// Load up the frames of our animation
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 8; ++i) {
[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"AnimBulle%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation animationWithFrames:walkAnimFrames
delay:0.1f];
[target runAction:_walkAction];
target.tag = 1;
[_targets addObject:target];
[self addBoxBodyForSprite:target];
[spriteSheet2 addChild:target z:0 tag:1];
id actionMove = [CCMoveTo actionWithDuration:actualDuration
position:ccp(240, 160)];
id actionMoveDone = [CCCallFuncN actionWithTarget:self
selector:@selector(spriteDone:)];
[target runAction:[CCSequence actions:actionMove, actionMoveDone, nil]];
}
EDIT:
From the kind of error you get (not enough stack traces), you have an inifinite recursion (i.e., a method that ends up calling itself, either directly or indirectly). The code in
spawnCatdoes not seem to entail such an infinite recursion, so the problem must be somewhere else.How do you call
spawnCat? could you put some NSLog traces in the methods that are executed to create the animation, so that you see if someone keeps calling itself?ORIGINAL ANSWER:
Are you sure this is what you meant?
I can’t see
_walkActioninitialization, but I would expect you do that after creating the animation by doing something like: