Cocos2d iphone COCOS2DV3.0-精灵表中的精灵动画
如何在cocos2dv3中使用SpriteAnimation 下面的代码在CoCoS2D2.0中有所帮助,现在出现了许多错误,如CCAnimationCache、CCAnimate not found。是否有使用精灵帧制作动画的CoCoS2D3.0示例Cocos2d iphone COCOS2DV3.0-精灵表中的精灵动画,cocos2d-iphone,Cocos2d Iphone,如何在cocos2dv3中使用SpriteAnimation 下面的代码在CoCoS2D2.0中有所帮助,现在出现了许多错误,如CCAnimationCache、CCAnimate not found。是否有使用精灵帧制作动画的CoCoS2D3.0示例 NSString *animName = @"FOG_ANIMATION"; CCAnimation* animation = nil; animation = [[CCAnimationCache sharedAnim
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 v3中使用CCAnimationCache:
#import "cocos2d.h"
#import "cocos2d-ui.h"
#import "CCAnimation.h"
#import "CCAnimationCache.h"
-(void)animateBird
{
NSString *animName = @"Bird_ANIM";
CCAnimation* animation = nil;
animation = [[CCAnimationCache sharedAnimationCache] animationByName:animName];
if(!animation)
{
NSMutableArray *animFrames = [NSMutableArray array];
for(int i=1;i<=8;i++)
{
NSString *file = [NSString stringWithFormat:@"Hero_01_Flap_%.2d.png",i];
CCSpriteFrame *frame = [cache spriteFrameByName:file];
if(frame)
{
[animFrames addObject:frame];
}
}
animation = [CCAnimation animationWithSpriteFrames:animFrames];
animation.delayPerUnit = 0.13f;// 0.1f;
animation.restoreOriginalFrame = NO;
[[CCAnimationCache sharedAnimationCache] addAnimation:animation name:animName];
}
CCActionAnimate *AnimAction = [CCActionAnimate actionWithAnimation:animation];
CCActionRepeatForever *repAction = [CCActionRepeatForever actionWithAction:AnimAction];
[bird runAction:repAction];
}
转到这个链接,它展示了如何制作spriteframe动画,希望这有帮助:D