我正在尝试制作静态动画,就像在电视上一样。我有 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];
最佳答案
您的帧数组应该是 CCSpriteFrame 对象(因为您拥有它们,所以它们是 NSString,并且没有 CCSpriteFrame 提供的方法,因此是无法识别的选择器)。查找here有关 Sprite 动画的良好介绍性教程。
关于objective-c - CCSprite运行 Action : crash.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10060551/