gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:30:39 28 4
gpt4 key购买 nike

你知道如何在新的 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]]];

有什么想法吗?

谢谢。


额外信息

enter image description here

最佳答案

它是这样工作的:

    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 - 如何在 Cocos2D 3.x 中为 CCSprite 制作动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21645953/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com