0
votes

I am trying to animate static, like on a tv. I have 5 frames, and I am trying to switch them out very quickly. Every time I run it, I get an unrecognized selector error and a crash. It crashes on [staticSprite runAction:repeat];. I am new at cocos2d.

CCLayer *staticlayer = [[CCLayer alloc]init];
staticlayer.contentSize = CGSizeMake(640, 960);
staticlayer.position = CGPointMake(winSize.width/2, winSize.height/2);
staticlayer.isRelativeAnchorPoint = YES;

NSArray *staticFrames = [[NSArray alloc]initWithObjects:@"static_0.jpg",
      @"static_1.jpg",@"static_2.jpg",@"static_3.jpg",@"static_4.jpg",nil];

CCSprite *staticSprite = [CCSprite spriteWithFile:@"static_0.jpg"];
staticSprite.position = ccp(winSize.width/2, winSize.height);

CCAnimation *staticAnimation = [CCAnimation animationWithFrames:staticFrames delay:0.1f];       
CCAnimate *staticAnimate = [CCAnimate actionWithAnimation:staticAnimation];

CCRepeatForever *repeat = [CCRepeatForever actionWithAction:staticAnimate];

[staticlayer addChild:staticSprite];
[self addChild:staticlayer z:0];
[staticSprite runAction:repeat];
1

1 Answers

1
votes

Your Array of frames should be CCSpriteFrame objects (as you have them they are NSString, and does not have the methods provided by a CCSpriteFrame, thus the unrecognized selector). Look up here for a good introductory turorial on sprite animations.