Как установить кадр анимации в cocos2d - PullRequest
2 голосов
/ 03 октября 2011

Я создал класс CCAnimationHelper, который выполняет следующее. Вы даете ему fileName, frameCount и Delay, и он возвращает вам анимацию. Я хочу знать, как установить кадр анимации, поэтому вместо того, чтобы начинать с кадра 1, он будет начинаться с кадра 10. Вот мой код

// 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
}

1 Ответ

1 голос
/ 03 октября 2011

Нет встроенной функции, которая делает это, но вы можете просто создать анимацию и передать ей NSArray, начиная с нужного кадра:

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