2011-05-23 55 views
3

我想知道如何将相机放在远处(通过增加和减少eyeZ self.camera setEyeX:0 eyeY:0 eyeZ:1];self.camera setEyeX:0 eyeY:0 eyeZ:180];的值),包括动画(用于平滑),通常它会提供焦急的缩放。放置相机与动画

+0

我想下面的链接将帮助你解决问题。 [基本动画](http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/AnimatingLayers.html)。看看那个页面中的**显式动画**。 – Ilanchezhian 2011-07-08 06:09:01

回答

0

如果从关闭中将“z”增加180,那么您肯定会得到一个生涩的动画,请尝试在动画上下文循环中运行此操作,在一段时间内增加值可以让您获得平滑'放大'。

+0

你刚才提到'你',你是真的吗?因为我使用Z来移动相机近和远。 – rptwsthi 2011-05-23 11:49:32

+0

对不起,我的确的意思是'Z' - 我已经相应地改变了答案。 – theiOSDude 2011-05-23 14:38:56

2

我的建议是创建自己的子类CCActionInterval,说CCCameraZoomAnimation并覆盖它的update方法。除了能够精确地控制摄像机移动之外,采取行动的主要优点还包括通过CCEaseOut/CCEaseIn(等)使用此操作以获得更好的图形效果的可能性。

CCCameraZoomAnimation将具有要修改其相机的节点作为目标,并将构造函数的另一个参数指定为最终的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's 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); 
    } 

没有更多,没有更多。

对不起,如果复制/粘贴/修改产生了一些错误,但我希望总体思路清晰。