在实现运动中,常常需要实现一些加速度或者减速度的效果。Cocos2D-x引擎为我们提供了相应的实现接口,这样就不用再用原来的公式计算方法实现加减速度的效果。
Ease系列的方法改变了运动的速度,但是并没有改变总体时间。如果整个动作持续5s,那么整个时间仍然会持续5s。这些动作可以分成三类,如下:
1、In actions:action(开始的时候加速)
2、Out actions:action(结束的时候加速)
3、InOut actions:action(开始和结束的时候加速)
CCActionEase有很多子类,根据不同的缓冲公式来模拟加减速过程,如下:
1、指数缓冲:分别为EaseExponentialIn、EaseExponentialOut/EaseExponentialInOut。
2、赛因缓冲:分别为:EaseSineIn、EaseSineOut、EaseSineInOut。
3、跳跃缓冲:分别为:EaseBouncelIn、EaseBouncelOut、EaseBouncelInOut。
4、弹性缓冲:分别为:EaseElasticIn、EaseElasticOut、EaseElasticInOut。
5、回震缓冲:分别为:EaseBackIn、EaseBackOut、EaseBackInOut。
使用示例如下:
1 //参数:缓冲动作(基本缓冲动作需要第二个参数是速率,弹性缓冲动作需要第二个参数是震动的周期)
2 //基本缓冲动作
3 CCEaseIn::create( (CCActionInterval*) (move->copy()->autorelease()), 2.5f );
4 CCEaseOut::create( (CCActionInterval*) (move->copy()->autorelease()), 2.5f );
5 CCEaseInOut::create( (CCActionInterval*) (move->copy()->autorelease()), 2.5f );
6
7 //指数缓冲动作
8 CCEaseExponentialIn::create( (CCActionInterval*) (move->copy()->autorelease()));
9 CCEaseExponentialOut::create( (CCActionInterval*) (move->copy()->autorelease()));
10 CCEaseExponentialInOut::create( (CCActionInterval*) (move->copy()->autorelease()));
11
12 //赛因缓冲动作
13 CCEaseSineIn::create( (CCActionInterval*) (move->copy()->autorelease()) );
14 CCEaseSineOut::create( (CCActionInterval*) (move->copy()->autorelease()) );
15 CCEaseSineInOut::create( (CCActionInterval*) (move->copy()->autorelease()) );
16
17 //跳跃缓冲动作
18 CCEaseBounceIn::create( (CCActionInterval*) (move->copy()->autorelease()) );
19 CCEaseBounceOut::create( (CCActionInterval*) (move->copy()->autorelease()) );
20 CCEaseBounceInOut::create( (CCActionInterval*) (move->copy()->autorelease()) );
21
22 //弹性缓冲动作
23 CCEaseElasticIn::create( (CCActionInterval*) (move->copy()->autorelease()) );
24 CCEaseElasticOut::create( (CCActionInterval*) (move->copy()->autorelease()) );
25 CCEaseElasticInOut::create( (CCActionInterval*) (move->copy()->autorelease()) , 0.3f);
26
27 //回震缓冲动作
28 CCEaseBackIn::create( (CCActionInterval*) (move->copy()->autorelease()) );
29 CCEaseBackOut::create( (CCActionInterval*) (move->copy()->autorelease()) );
30 CCEaseBackInOut::create( (CCActionInterval*) (move->copy()->autorelease()) );