Skip to content

Instantly share code, notes, and snippets.

@mzaks
Created October 17, 2012 14:56
Show Gist options
  • Save mzaks/3905976 to your computer and use it in GitHub Desktop.
Save mzaks/3905976 to your computer and use it in GitHub Desktop.
CCAnimate+AsymetricalStart
//
// CCAnimate+AsymetricalStart.m
// CocosAnimatioPrototype
//
// Created by Maxim Zaks on 17.10.12.
// Copyright (c) 2012 Maxim Zaks. All rights reserved.
//
#import "CCAnimate+AsymetricalStart.h"
#import "CCAnimation.h"
@implementation CCAnimate (AsymetricalStart)
- (CCAnimation *) shortVersion
{
NSArray *oldArray = [animation_ frames];
NSUInteger oldCount = [oldArray count];
NSUInteger startFrom = arc4random() % oldCount;
NSArray *newArray = [oldArray subarrayWithRange:NSMakeRange(startFrom, oldCount-startFrom)];
CCAnimation *newAnim = [CCAnimation animationWithAnimationFrames:newArray
delayPerUnit:animation_.delayPerUnit
loops:animation_.loops];
return [[self class] actionWithAnimation:newAnim];
}
@end
//
// CCAnimate+AsymetricalStart.m
// CocosAnimatioPrototype
//
// Created by Maxim Zaks on 17.10.12.
// Copyright (c) 2012 Maxim Zaks. All rights reserved.
//
#import "CCAnimate+AsymetricalStart.h"
#import "CCAnimation.h"
@implementation CCAnimate (AsymetricalStart)
- (CCAnimate *) shortVersion
{
NSArray *oldArray = [animation_ frames];
NSUInteger oldCount = [oldArray count];
NSUInteger startFrom = arc4random() % oldCount;
NSArray *newArray = [oldArray subarrayWithRange:NSMakeRange(startFrom, oldCount-startFrom)];
CCAnimation *newAnim = [CCAnimation animationWithAnimationFrames:newArray
delayPerUnit:animation_.delayPerUnit
loops:animation_.loops];
return [[self class] actionWithAnimation:newAnim];
}
@end
// Basic usage example
[mySprite runAction:[CCSequence actions:[animation shortVersion], [CCCallBlock actionWithBlock:^{
[mySprite runAction:[CCRepeatForever actionWithAction: animation]];
}], nil]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment