Created
October 17, 2012 14:56
-
-
Save mzaks/3905976 to your computer and use it in GitHub Desktop.
CCAnimate+AsymetricalStart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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