0

我正在尝试为静态设置动画,例如在电视上。我有 5 帧,我正在尝试快速切换它们。每次运行它时,我都会收到无法识别的选择器错误和崩溃。它崩溃了[staticSprite runAction:repeat];。我是 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];
4

1 回答 1

1

您的帧数组应该是 CCSpriteFrame 对象(因为您拥有它们,它们是 NSString,并且没有 CCSpriteFrame 提供的方法,因此是无法识别的选择器)。在此处查找有关精灵动画的良好介绍性教程。

于 2012-04-08T13:43:07.050 回答