iphone - cocos2d中如何设置动画的帧

标签 iphone animation cocos2d-iphone box2d

我制作了一个执行以下操作的 CCAnimationHelper 类。你给它一个文件名、一个帧计数和一个延迟,它就会给你返回一个动画。我想知道的是如何设置动画的帧,这样它将从第 10 帧开始,而不是从第 1 帧开始。这是我的代码

// Creates an animation from sprite frames.
+(CCAnimation*) animationWithFrame:(NSString*)frame frameCount:(int)frameCount delay:(float)delay
{
// load the ship's animation frames as textures and create a sprite frame
NSMutableArray* frames = [NSMutableArray arrayWithCapacity:frameCount];
for (int i = 1; i < frameCount; i++)
{
    NSString* file = [NSString stringWithFormat:@"%@%i.png", frame, i];
    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
    CCSpriteFrame* frame = [frameCache spriteFrameByName:file];
    [frames addObject:frame];
}

// return an animation object from all the sprite animation frames
return [CCAnimation animationWithFrames:frames delay:delay]; //Is there another method I should be using here to set the frame
}

最佳答案

没有内置函数可以做到这一点,但您可以简单地创建动画并从您想要的帧开始将 NSArray 传递给它:

    CCAnimation *animation = [CCAnimation animation];
    NSArray *offset = [NSArray arrayWithObjects:frame3, frame4, nil];
    [animation initWithFrames:offset];

关于iphone - cocos2d中如何设置动画的帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7629749/

相关文章:

android - android View 转换动画列表?

iphone - 使用cocos2d在iPhone游戏中实现3D透视图

iphone - 如何修复 "Error: (-12646:0) Illegal MIME type: text/plain"

android - 在android中使用按钮加载动画

swift - 如何使用动画仅转换 View 的按钮边缘

iphone - 声音引擎泄漏……预加载是一种不好的做法吗?

iphone - Sprite 上的无限滚动(视差)

ios - 将动态库注入(inject)企业应用程序(ipa)

iphone - Objective-C中如何获取外部IP

ios - UISplitViewController 中的自定义 UIBarButtonItem 不响应点击 (iPhone)