0

我怎样才能为这个精灵设置动画?

if ((self = [super initWithSpriteFrameName:@"Boss_ship_5.png" world:world shapeName:@"Boss_ship" maxHp:50 healthBarType:HealthBarTypeRed])) {

我正在尝试这个,但是 _layer 不起作用......

CCSpriteFrameCache * cache =
[CCSpriteFrameCache sharedSpriteFrameCache];

CCAnimation *animation = [CCAnimation animation];

[animation addSpriteFrame:
    [cache spriteFrameByName:@"Boss_ship_5.png"]];

[animation addSpriteFrame:
    [cache spriteFrameByName:@"Boss_ship_4.png"]];
animation.delayPerUnit = 0.05;

[_layer runAction:
    [CCRepeatForever actionWithAction:
        [CCAnimate actionWithAnimation:animation]]];
4

1 回答 1

1

在将精灵添加到animation对象之前,您需要将纹理加载到CCSpriteFrameCache. 请看一下

http://www.cocos2d-iphone.org/archives/633

此外,CCAnimation动作应该与CCSprites. 哪个类是_layer对象?

于 2013-04-10T22:22:53.057 回答