cocos2d/cocos2d-iphone — pull request #249 by rsanchezsaez (2012-10-17 17:33:33+00:00)
Title: CCAnimate action improvements

##### Description

Added new designated initialiser

+(id)actionWithAnimation:(CCAnimation*)action startFrameIndex:(NSInteger)start

It allows choosing an animation start frame (and will cycle until it reaches the chosen frame minus one).

Added

+(id)actionWithRandomStartAnimation:(CCAnimation*)action
+(id)actionWithRandomStartAnimation:(CCAnimation*)action

They allow you to randomise the animation cycle. Useful for starting several animation at the same time but having them unsynchronized.

Added Test for the new methods to the SpriteTest suite (SpriteAnimationSplitRandom).

Also made a small fix/optimization to CCAnimate update (the break was not in the correct place, so it would not skip frames correctly on low framerates).

##### Examples:

Given an 'animation' with 5 frames, running

[CCAnimate actionWithAnimation:aniation startFrameIndex:3]

will show frames in this order: 3, 4, 0, 1, 2

Given an 'animation' with 10 frames, running

[CCAnimate actionWithRandomStartAnimation:animation factor:0.2]

will chose a random startFrameIndex within the range [0, 1].

Given an 'animation' with 10 frames, running

[CCAnimate actionWithRandomStartAnimation:animation factor:0.4]will chose a random

startFrameIndex within the range [0, 1, 3, 4]