【发布时间】:2014-03-29 05:40:26
【问题描述】:
如何在Cocos2d v3中使用SpriteAnimation?
以下代码在 cocos2d 2.0 中有所帮助,现在出现许多错误,例如 CCAnimationCache、CCAnimate not found。有没有使用精灵帧动画的 cocos2d 3.0 示例?
NSString *animName = @"FOG_ANIMATION";
CCAnimation* animation = nil;
animation = [[CCAnimationCache sharedAnimationCache] animationByName:animName];
if(!animation)
{
NSMutableArray *animFrames = [NSMutableArray array];
CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];
for(int i=1;i<=18;i++)
{
NSString *file = [NSString stringWithFormat:@"Steam_%.2d.png",i];
CCSpriteFrame *frame = [cache spriteFrameByName:file];
if(frame)
{
[animFrames addObject:frame];
}
}
animation = [CCAnimation animationWithSpriteFrames:animFrames];
animation.delayPerUnit = DELAY_PER_FRAME_HERO_RUN;// 0.1f;
animation.restoreOriginalFrame = NO;
[[CCAnimationCache sharedAnimationCache] addAnimation:animation name:animName];
}
CCAnimate *AnimAction = [CCAnimate actionWithAnimation:animation];
CCRepeatForever *repAction = [CCRepeatForever actionWithAction:AnimAction];
[steam runAction:repAction];
【问题讨论】:
标签: cocos2d-iphone