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

elp*_*elp 7 objective-c cocos2d-iphone ios

你知道如何CCSprite在新的Cocos2D v3.x中制作动画吗?

许多类都被改变了,旧的方法似乎不起作用.

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]]];
Run Code Online (Sandbox Code Playgroud)

任何的想法?

谢谢.


额外信息

在此输入图像描述

Ben*_*n-G 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];
Run Code Online (Sandbox Code Playgroud)

  • 只是为了将来参考如果导入cocos2d没有问题导入`#import"CCAnimation.h"`它对我有用 (2认同)