【问题标题】:CCSprite runAction: crash.CCSprite runAction:崩溃。
【发布时间】:2012-04-08 05:09:34
【问题描述】:

我正在尝试为静态设置动画,例如在电视上。我有 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];

【问题讨论】:

    标签: objective-c ios animation cocos2d-iphone


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      相关资源
      最近更新 更多