微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/iOS/332014.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐