Yes, of course, I can even show you the code :
#import "RA_CCSyncedAnimates.h"
@implementation RA_CCSyncedAnimates
@synthesize animationMaster = animationMaster_;
@synthesize animationSlave = animationSlave_;
@synthesize targetSlave = targetSlave_;
+(id) actionWithDuration:(ccTime)duration animationMaster:(id<CCAnimationProtocol>)animMaster animationSlave:(id<CCAnimationProtocol>)animSlave targetSlave:(id)targetSlave
{
return [[[self alloc] initWithDuration:duration animationMaster:animMaster animationSlave:animSlave targetSlave:targetSlave] autorelease];
}
-(id) initWithDuration:(ccTime)Duration animationMaster:(id<CCAnimationProtocol>)animMaster animationSlave:(id<CCAnimationProtocol>)animSlave targetSlave:(id)targetSlave
{
NSAssert( animMaster!=nil, @"Animate: argument animMaster must be non-nil");
NSAssert( animSlave!=nil, @"Animate: argument animSlave must be non-nil");
NSAssert( targetSlave!=nil, @"Animate: argument targetSlave must be non-nil");
#ifdef COCOS2D_DEBUG
NSArray *framesMaster = [animMaster frames];
NSUInteger numberOfMasterFrames = [framesMaster count];
NSArray *framesSlave = [animSlave frames];
NSUInteger numberOfSlaveFrames = [framesSlave count];
NSAssert(numberOfMasterFrames == numberOfSlaveFrames, @"Trying to sync 2 animations with different frame number");
#endif //COCOS2D_DEBUG
if( (self=[super initWithDuration:Duration] ) )
{
self.animationMaster = animMaster;
self.animationSlave = animSlave;
targetSlave_ = targetSlave;
}
return self;
}
-(id) copyWithZone: (NSZone*) zone
{
return [[[self class] allocWithZone: zone] initWithDuration:duration animationMaster:animationMaster_ animationSlave:animationSlave_ targetSlave:targetSlave_];
}
-(void) dealloc
{
[animationMaster_ release];
[animationSlave_ release];
[super dealloc];
}
-(void) startWithTarget:(id)aTarget
{
[super startWithTarget:aTarget];
}
-(void) stop
{
[super stop];
}
-(void) update: (ccTime) t
{
NSUInteger idx=0;
NSArray *framesMaster = [animationMaster_ frames];
NSUInteger numberOfMasterFrames = [framesMaster count];
NSArray *framesSlave = [animationSlave_ frames];
#ifdef COCOS2D_DEBUG
NSUInteger numberOfSlaveFrames = [framesSlave count];
NSAssert(numberOfMasterFrames == numberOfSlaveFrames, @"update : Trying to sync 2 animations with different frame number");
#endif //COCOS2D_DEBUG
ccTime slice = 1.0f / numberOfMasterFrames;
if(t !=0 )
idx = t/ slice;
if( idx >= numberOfMasterFrames ) {
idx = numberOfMasterFrames -1;
}
id<CCFrameProtocol> spriteMaster = (id<CCFrameProtocol>) target;
id<CCFrameProtocol> spriteSlave = (id<CCFrameProtocol>) targetSlave_;
if (! [spriteMaster isFrameDisplayed: [framesMaster objectAtIndex: idx]] ) {
[spriteMaster setDisplayFrame: [framesMaster objectAtIndex:idx]];
[spriteSlave setDisplayFrame: [framesSlave objectAtIndex:idx]];
}
}
/*- (CCIntervalAction *) reverse
{
NSArray *oldArray = [animation_ frames];
NSMutableArray *newArray = [NSMutableArray arrayWithCapacity:[oldArray count]];
NSEnumerator *enumerator = [oldArray reverseObjectEnumerator];
for (id element in enumerator) {
[newArray addObject:[[element copy] autorelease]];
}
CCAnimation *newAnim = [CCAnimation animationWithName:animation_.name delay:animation_.delay frames:newArray];
return [[self class] actionWithDuration:duration animation:newAnim restoreOriginalFrame:restoreOriginalFrame];
}*/
@end
It's based on CCAnimate of course, and it's a rough implementation that suits my need only (sync of only 2 animations, no reverse, not very safe handling of the second target, ...)
If you have any question about it, feel free to ask :).