您知道如何在新的 Cocos2D v3.x 中为CCSprite
添加动画效果吗?
许多类都被更改了,旧方法似乎无法正常工作。
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i <= 3; i++) {
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Sprite-%d.png",i]];
[animFrames addObject:frame];
}
CCAnimation *animation = [CCAnimation animationWithName:@"run" delay:0.1f frames:animFrames];
[mySprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO]]];
任何想法?
感谢。
答案 0 :(得分:6)
这是它的工作原理:
NSMutableArray *animationFrames = [NSMutableArray array];
for(int i = 1; i <= FRAMES; ++i)
{
CCSpriteFrame *spriteFrame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"animationFrame%d.png", i]]; //
}
//Create an animation from the set of frames you created earlier
CCAnimation *animation = [CCAnimation animationWithSpriteFrames: animationFrames delay:delay];
//Create an action with the animation that can then be assigned to a sprite
CCActionAnimate *animationAction = [CCActionAnimate actionWithAnimation:animation];
CCActionRepeatForever *repeatingAnimation = [CCActionRepeatForever actionWithAction:animationAction];
[self runAction:repeatingAnimation];
答案 1 :(得分:1)
您可以将CCRepeatForever
更改为CCActionRepeatForever
。