I am trying to create a CCSprite subclass called Enemy
#import "Enemy.h"
@implementation Enemy
{
CCSprite* ant;
CCAnimation *walkAnim ;
}
-(id)init
{
self = [super init];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"char.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"char.png"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for (int i=1; i<=3; i++) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"antNormal_%d.png",i]]];
}
walkAnim = [CCAnimation animationWithSpriteFrames:walkAnimFrames delay:0.1f];
self = [CCSprite spriteWithSpriteFrameName:@"antNormal_1.png"];
CCAction* walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim]];
[self runAction:walkAction];
return self;
}
@end
and then in my gamelayer I have the enemies added like this
enemies=[[CCArray alloc] initWithCapacity:100];
for (int i=0; i<10; i++) {
Enemy* ant=[[Enemy alloc] init];
[ant setPosition:ccp(100*i,100)];
[enemies addObject:ant];
}
But this is causing the program to crash on start with the error
'NSInternalInconsistencyException', reason: 'Animate: argument Animation must be non-nil'
If I comment out the CCAction though, the enemies display correctly, just without animation(obviously). Not sure how to solve this at the moment.