0
votes

How can I animate this sprite?

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

I'm trying with this, but with _layer doesn't work...

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]]];
1

1 Answers

1
votes

Before adding sprites to animation object, you'll need to load the textures into the CCSpriteFrameCache. Please, take a look at

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

Also, CCAnimation actions are supposed to be used with CCSprites. Which class is _layer object?