Placement of the camera with animation

I want to know how to place the camera near and far (increasing and decreasing the value of eyeZ self.camera setEyeX:0 eyeY:0 eyeZ:1]; self.camera setEyeX:0 eyeY:0 eyeZ:180];), including animation (for smoothness), since it usually provides a sharp zoom.

+3
source share
2 answers

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;
 }
 /** creates the action */
 +(id) actionWithDuration:(ccTime)t finalZ:(float)finalZ;
 /** initializes the action */
 -(id) initWithDuration:(ccTime)t finalZ:(float)finalZ;
 @end

update dt, Z:

 -(void) update: (ccTime) t
 {
    // Get the camera current values.
    float centerX, centerY, centerZ;
    float eyeX, eyeY, eyeZ;
    [_target.camera centerX:&centerX centerY:&centerY centerZ:&centerZ];
    [_target.camera eyeX:&eyeX eyeY:&eyeY eyeZ:&eyeZ];

    eyeZ = _intialZ + _delta * t  //-- just a try at modifying the camera

    // Set values.
    [_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....;  //-- get the current value for eyeZ
      _delta = ccpSub( _finalZ, _initialZ );
  }

, .

, // , , .

+2

'z' 180 ., , , , .

0

All Articles