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

Actions: Ease

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

 

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

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

E

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:

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 MoveByScaleByRotateBy 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 MoveByScaleByRotateBy 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 MoveByScaleByRotateBy 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)


posted @ 2010-01-24 19:03  AlexLiu  阅读(10466)  评论(0编辑  收藏  举报