My suggestion creates your own subclass CCActionInterval, say CCCameraZoomAnimationand overrides its method update. The main advantage of having an action, in addition to being able to control the cameraβs movement finely, also allows you to use this action through CCEaseOut/ CCEaseIn(etc.) to get good graphic effects.
CCCameraZoomAnimation node , , , Z.
@interface CCActionEase : CCActionInterval <NSCopying>
{
CCActionInterval * other;
}
+(id) actionWithDuration:(ccTime)t finalZ:(float)finalZ;
-(id) initWithDuration:(ccTime)t finalZ:(float)finalZ;
@end
update dt, Z:
-(void) update: (ccTime) t
{
float centerX, centerY, centerZ;
float eyeX, eyeY, eyeZ;
[_target.camera centerX:¢erX centerY:¢erY centerZ:¢erZ];
[_target.camera eyeX:&eyeX eyeY:&eyeY eyeZ:&eyeZ];
eyeZ = _intialZ + _delta * t
[_target.camera setCenterX:newX centerY:newY centerZ:0];
[_target.camera setEyeX:newX eyeY:newY eyeZ:eyeZ];
}
copyWithZone:
-(id) copyWithZone: (NSZone*) zone
{
CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] finalZ:_finalZ];
return copy;
}
startWithTarget
-(void) startWithTarget:(CCNode *)aTarget
{
[super startWithTarget:aTarget];
_initialZ = _target.camera....;
_delta = ccpSub( _finalZ, _initialZ );
}
, .
, // , , .