本文介绍了如何在 Cocos2D 3.x 中为 CCSprite 设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你知道如何在新的 Cocos2D v3.x 中为 CCSprite
制作动画吗?
do you know how to animate a CCSprite
in the new Cocos2D v3.x ?
很多类都改了,老方法好像不行了.
A lot of classes are changed, and old method seems not work.
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];
这篇关于如何在 Cocos2D 3.x 中为 CCSprite 设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!