holydancer原创,如需转载,请在显要位置注明:
转自holydancer的CSDN专栏,原文地址:http://blog.csdn.net/holydancer/article/details/8489540
用CCActionEase来对动作进行修饰
CCActionEase继承自CCActionInterval,层次图如图所示:
该类用于更灵活的使用动作,所以我习惯称为对动作的修饰类,之所以这样叫也是因为CCActionEase在生成时是在已有的action上又包了一层(actionWithAction),而节点调用时也是直接将其作为动作来调用的;大家随便怎么叫吧,知道有这么个玩意儿就行了;
CCEaseBackIn
在正常runAction前会有一个拉后的动作;
示例:
CCEaseBackIn *ease = [CCEaseBackInactionWithAction:[CCMoveByactionWithDuration:3position:ccp(200,0)]];
[sprite runAction:ease];
//效果为精灵在往向移动200之前先向左移动一部分;
CCEaseBackInOut
修饰前的动作运行前向后,运行结束后回弹,注意,这里回弹是超过设定的移动距离再弹回;
CCEaseBackIn *ease = [CCEaseBackInOut actionWithAction:[CCMoveBy actionWithDuration:3 position:ccp(200,0)]];
[sprite runAction:ease];
CCEaseBackOut
修饰前的动作运行结束后弹回
CCEaseBackOut *ease = [CCEaseBackOut actionWithAction:[CCMoveBy actionWithDuration:3 position:ccp(200,0)]];
[sprite runAction:ease];
CCEaseBounceIn
修饰前的动作结束前有三次回到起点的跳跃(自己总结的,大家还是自己看看效果好)
CCEaseBounceIn *ease = [CCEaseBounceInactionWithAction:[CCMoveByactionWithDuration:10position:ccp(200,0)]];
[sprite runAction:ease];
CCEaseBounceOut
修饰前的动作结束后往之前的运行轨迹上跳跃三次
CCEaseBounceOut *ease = [CCEaseBounceOutactionWithAction:[CCMoveByactionWithDuration:10position:ccp(200,0)]];
[sprite runAction:ease];
CCEaseBounceInOut
结合了上面两种效果
CCEaseBounceInOut *ease = [CCEaseBounceInOutactionWithAction:[CCMoveByactionWithDuration:10position:ccp(200,0)]];
[sprite runAction:ease];
CCEaseElasticIn
与CCEaseBounceIn效果类似,不过不是跳跃,是渐快的移动;
CCEaseElasticIn *ease = [CCEaseElasticInactionWithAction:[CCMoveByactionWithDuration:10position:ccp(200,0)]];
[sprite runAction:ease];
CCEaseElasticOut
与CCEaseBounceOut效果类似,依然是渐快的弹性移动;
CCEaseElasticOut *ease = [CCEaseElasticOutactionWithAction:[CCMoveByactionWithDuration:10position:ccp(200,0)]];
[sprite runAction:ease];
CCEaseElasticInOut
结合了上面两种效果;
CCEaseIn
这是比较早的版本就存在的类库了,在运动的结尾突然加速
CCEaseOut
在运动一开始就突然加速;
CCEaseInOut
由慢到快,再由快到慢,注意这三个是CCEaseRateAction的子类,有一个方法
CCEaseIn actionWithAction:action rate:rate 是可以调节rate作为速率的
还有一些CCEase效果,不过因为不常用,或者我也把握不准,试不出来效果,这里就不列了;
CCSequence从CCActionInterval继承而来,使用方法类似于一个array,可以在里面添加几个动作,使其动作一个接一个运行(one after another),例如
CCEaseBounceOut *ease = [CCEaseBounceOut actionWithAction:[CCMoveBy actionWithDuration:3 position:ccp(100,0)]]; CCJumpBy *jump = [CCJumpBy actionWithDuration:3 position:ccp(50,0) height:50 jumps:3]; CCSequence *sequence = [CCSequence actions:ease,jump, nil]; [sprite runAction:sequence];
注意添加动作序列时需要以nil为结尾,ios开发同学应该很熟悉这种操作;
使用回调动作CCCallFunc在动作序列中添加方法回调
一个动作序列中一个动作一个动作之间,如果我们想要调用某个方法,可以使用CCCallFunc来进行,使用方法如下:
先添加一个方法(无参数)
-(void)callBackTest { CCLOG(@"!!!!!!"); }
CCEaseBounceOut *ease = [CCEaseBounceOut actionWithAction:[CCMoveBy actionWithDuration:3 position:ccp(100,0)]]; CCJumpBy *jump = [CCJumpBy actionWithDuration:3 position:ccp(50,0) height:50 jumps:3]; CCCallFunc *func = [CCCallFunc actionWithTarget:self selector:@selector(callBackTest)]; CCSequence *sequence = [CCSequence actions:ease,func,jump, nil]; [sprite runAction:sequence];
除了CCCallFunc,还有CCCallFuncN,CCCallFuncND可以使用,三者之间有一定的区别;CCCallFunc调用的方法没有参数,后两者分别有一个,两个参数且固定的第一个参数都是sender本身;
-(void)onCallFunc
{ }
-(void)onCallFuncN:(id)sender
{ }
-(void)onCallFuncND:(id)sender data:(void *)data
{ }