0

我正在使用这段代码来动画这个精灵:

_ship = [[GameObject alloc] initWithSpriteFrameName:@"SpaceFlier_sm_1.png" world:_world shapeName:@"SpaceFlier_sm_1" maxHp:10 healthBarType:HealthBarTypeGreen];

     CCSpriteFrameCache * cache =
    [CCSpriteFrameCache sharedSpriteFrameCache];

    CCAnimation *animation = [CCAnimation animation];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"SpaceFlier_s_2.png"]];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"SpaceFlier_s_3.png"]];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"SpaceFlier_s_4.png"]];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"SpaceFlier_s_5.png"]];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"SpaceFlier_s_6.png"]];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"SpaceFlier_s_7.png"]];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"SpaceFlier_s_8.png"]];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"SpaceFlier_s_2.png"]];


    animation.delayPerUnit = 0.05;

    [_ship runAction:
     [CCRepeatForever actionWithAction:
      [CCAnimate actionWithAnimation:animation]]];

它工作得很好。然后,当我尝试使用此代码为另一个精灵设置动画时,它不起作用。

这样:

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

    CCSpriteFrameCache * cache =
    [CCSpriteFrameCache sharedSpriteFrameCache];

    CCAnimation *animation = [CCAnimation animation];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"dragon2.png"]];
    [animation addSpriteFrame:
     [cache spriteFrameByName:@"dragon.png"]];



    animation.delayPerUnit = 0.05;

    [self runAction:
     [CCRepeatForever actionWithAction:
      [CCAnimate actionWithAnimation:animation]]];

我只能看到dragon2.png,它不会改变dragon,png ...

4

1 回答 1

0

检查它dragon.png是否在您的精灵图集或捆绑资源中。此外,请仔细检查文件名中的大小写是否与您的字符串完全匹配。

于 2013-04-11T14:07:57.163 回答