cocos2d-基本概念(3)-Actions: Ease 缓冲动作

本文深入探讨了Cocos2d-X中的动作缓存(Ease)与速度调整(Speed)机制,包括缓存动作的分类(如EaseIn、EaseOut、EaseInOut等)、指数缓冲(EaseExponential)、塞因缓冲(EaseSine)、弹性缓冲(EaseElastic)、跳跃缓冲(EaseBounce)与Back缓冲。同时,解释了如何通过设置率参数(rate)来调整动作的速度,确保动作的总持续时间保持不变。最后,提供了多个示例代码,帮助开发者实现各种动态效果。

Actions: Ease

  ease 不知道怎么翻译,暂时翻译成缓冲操作吧。这个chapter大概的意思就是对移动等动作进行封装路线的变化,或者是从原来的在总的持续时间不变的前提下,变成了非匀速的运动。需要说名的一点就是,这个wiki里面提到的部分内容,现在最新版本的cocos2d里面已经找不到了,函数的说明变了。。。对于找不到的,暂时不翻译,反正也比较简单,照猫画虎把。哈哈。

  缓冲操作是一个特殊的复杂操作,可以改变inner 动作的时间。在Flash里面,它们经常被称作Tweening 或者Easing 动作。

  它们虽然改变了运动的速度,但是并没有改变总体时间,如果整个的action持续5秒钟,那么整个的时间仍然会持续5秒钟。 

  The Ease actions alter the linearity of the time.

例如它们可以对inner的action进行加速或者是减速。 

  这些action可以被分成3类: 

  In actions: action开始的时候加速

  Out actions: action结束的时候加速

  InOut actions: action开始,结束的时候加速

  For more information about easing or tweening actions, visit any of these pages:

  http://hosted.zeh.com.br/tweener/docs/en-us/misc/transitions.html

  http://www.robertpenner.com/easing/easing_demo.html

  Ease actions

这些内部的action是按着如下进行加速的:

-(void) update:(ccTime) t 
{ 
  [inner update: powf(t,rate)]; 
}

rate 这个参数就是增加的速率

  以下举了几个例子说明的分别的动作的开始,结束,和开始或者结束的时候加速。 

  Example:

// acceleration at the beginning
        id action = [MoveTo actionWithDuration:2 position:ccp(100,100)];
 id ease = [EaseIn actionWithAction:action rate:2];
 [sprite runAction: ease];
 
 // acceleration at the end
 id action = [MoveTo actionWithDuration:2 position:ccp(100,100)];
 id ease = [EaseIn actionWithAction:action rate:2];
 [sprite runAction: ease];
 
 // acceleration at the beginning / end
 id action = [MoveTo actionWithDuration:2 position:ccp(100,100)];
 id ease = [EaseInOut actionWithAction:action rate:2];
 [sprite runAction: ease];

EaseExponential actions 指数缓冲动作

EaseExponentialIn

  EaseExponentialOut

  EaseExponentialInOut

  EaseSine actions 塞因缓冲

     

  EaseSineIn

  EaseSineOut

  EaseSineInOut

  接下来的几个Ease的action,在最新版本的cocos2d里面找不到了,貌似已经干掉了。不理解了。。可以我从xcode拿出来的code,就知道了,以下的这几个关键字已经不变色了。。

就剩下一个rate的了。

  [EaseRateAction actionWithAction:<#(IntervalAction *)action#> rate:<#(float)rate#>]; 

  EaseElastic actions 弹性缓冲

These actions alters the time simulating an elastic. Elastic actions will use time values greater than 1 and lower than 0, so the inner action should be prepared to handle this special values.

  Also some values will be triggered more than once (this function is not bijective), so again, the inner action should be prepared to handle this values. Simple actions like MoveBy, ScaleBy, RotateBy work OK with EaseElastic actions, but the Sequence or Spawnactions might have unexpected results.

  Available since v0.8.2

  Available elastic actions:

  EaseElasticIn

  EaseElasticOut

  EaseElasticInOut

  Examples:

// 'period' is how elastic is the action.
 
// recommended values: between 0.3 and 0.45
 
 
// Elastic at the beginning
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseElasticIn actionWithAction:move period:0.3f];
 [sprite runAction: action];
 
 // Elastic at the end
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseElasticOut actionWithAction:move period:0.3f];
 [sprite runAction: action];
 
 // Elastic at the beginning and at the end
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseElasticInOut actionWithAction:move period:0.3f];
 [sprite runAction: action];

EaseBounce actions 跳跃缓冲

EaseBounce actions simulates a bouncing effect.

  Some time values will be triggered more than once (this function is not bijective), so the inner action should be prepared to handle this values. Simple actions like MoveBy, ScaleBy, RotateBy work OK with EaseBounce actions, but the Sequence or Spawn actions might have unexpected results.

  Available since v0.8.2

  Available bounce actions:

  EaseBounceIn

  EaseBounceOut

  EaseBounceInOut

  Examples:

// Bounce at the beginning
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseBounceIn actionWithAction:move];
 [sprite runAction: action];
 
 // Bounce at the end
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseBounceOut actionWithAction:move];
 [sprite runAction: action];
 
 // Bounce at the beginning and at the end
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseBounceInOut actionWithAction:move];
 [sprite runAction: action];

EaseBack actions

 Some time values will be triggered more than once (this function is not bijective), so the inner action should be prepared to handle this values. Simple actions like MoveBy, ScaleBy, RotateBy work OK with EaseBack actions, but the Sequence or Spawn actions might have unexpected results.

  Available since v0.8.2

  Available bounce actions:

  EaseBackIn

  EaseBackOut

  EaseBackInOut

  Examples:

// Back at the beginning
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseBackIn actionWithAction:move];
 [sprite runAction: action];
 
 // Back at the end
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseBackOut actionWithAction:move];
 [sprite runAction: action];
 
 // Back at the beginning and at the end
 id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [EaseBackInOut actionWithAction:move];
 [sprite runAction: action];

 Actions: Speed

  Speed action

  The Speed action modifies the duration of the inner action.

id move = [MoveBy actionWithDuration:3 position:ccp(350,0)];
 id action = [Speed actionWithAction: move speed:1.0f];   // no speed modification
 
 
// but you can modify the speed later
 [action setSpeed: 2.5f]; // speed is 2.5 faster
 
 [action setSpeed: 0.5f]; // speed is 0.5 faster (it means 2 times slower)

 出处:http://alexliu.cnblogs.com/


 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值