ios – 如何在Cocos2D 3.x中为CCSprite制作动画?

前端之家收集整理的这篇文章主要介绍了ios – 如何在Cocos2D 3.x中为CCSprite制作动画?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
你知道如何在新的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]]];

任何的想法?

谢谢.

额外信息

解决方法

这是它的工作原理:
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];

猜你在找的iOS相关文章