前几天就是懒了,白天上课,然后晚上回来几乎也弄不了什么就睡了,所以就没发什么,今天总算打起精神继续学习了。我们今天说CCAction包括,CCAction,CCFiniteTimeAction,CCSpeed,CCFollow,
我们开始吧,上图:
首先CCAction分成三类,分别是CCFiniteTimeAction,CCSpeed,和CCFollow
CCFiniteTimeAction又分成两类,上图的CCAction应该写成CCFiniteTimeAction,
CCFiniteTimeAction包括CCActionInstant(瞬时动作),CCActionInterval(延时动作)
瞬时动作又包括以上的几种,这些动作都是在一瞬间完成的,我们看不见变换的过程,应为他太快了。你可能会问CCPlace和setPosition不都差不多嘛,何必多此一举来用CCPlace还包装成一个action,其实这些都可以封装成为一个顺序,这不正是CCPlace和setPosition的区别了吗。
代码示例:
CCFlipY *flipx = CCFlipY::create(true); CCHide *hide = CCHide::create(); CCToggleVisibility *togglevis = CCToggleVisibility::create(); CCPlace *place = CCPlace::create(ccp(200,200));
以上的几种相对难理解的是假动作CCCallFunc,所以我们具体说说这个。假动作就是没有动作,其实他只是一个回调。
<span style="font-size:24px;">CCCallFunc *callfun = CCCallFunc::create(this,callfunc_selector(T14CCActionDemo::funcall)); CCCallFuncN *callfunc = CCCallFuncN::create(this,callfuncN_selector(T14CCActionDemo::funcallN)); CCCallFuncND *callfuncnd = CCCallFuncND::create(this,callfuncND_selector(T14CCActionDemo::funcallND),(void *)("90")); CCCallFuncO *callfunco = CCCallFuncO::create(this,callfuncO_selector(T14CCActionDemo::funcallO),woman);</span>
void T14CCActionDemo::funcall() { CCLog("action is ok"); } void T14CCActionDemo::funcallN(CCNode* node) { node->setVisible(false); } void T14CCActionDemo::funcallND(CCNode* pnode,void* pdata) { CCString *str = CCString::createWithFormat("%s",pdata); pnode->setRotation(str->floatValue()); } void T14CCActionDemo::funcallO(CCObject* obj) { CCSprite *woman = (CCSprite *)obj; CCMoveBy *moveby = CCMoveBy::create(2,ccp(200,0)); woman->runAction(moveby); }
CCCallFunc是一个最基础的假动作,CCCallFuncN可以在回调的时候得到CCNode,CCCallFuncND可以在回调的时候得到CCNode,和Data,Data就是我们手动加的数据,上面的例子就是那个"90"的字符串啊。CCCallFuncO就是可以在会掉的时候得到我们定义的CCObject。
这上面的全部都是延时动作,贴上示例代码:
CCMoveTo *moveto = CCMoveTo::create(3,ccp(300,100)); CCMoveBy *moveby = CCMoveBy::create(2,0)); CCMoveBy *moveby2 = CCMoveBy::create(2,0)); CCJumpTo *jumpto = CCJumpTo::create(3,100),50,3); CCJumpBy *jumpby = CCJumpBy::create(3,0),150,3); CCScaleTo *scaleTo = CCScaleTo::create(3,2); CCScaleBy *scaleby = CCScaleBy::create(3,2); CCRotateTo *rotateto = CCRotateTo::create(3,-90); CCRotateBy *rotateBy = CCRotateBy::create(3,-90); CCSpawn *spawn = CCSpawn::create(rotateto,scaleby,NULL); CCSequence *sequence = CCSequence::create(rotateto,NULL); CCSkewTo *skewto = CCSkewTo::create(3,222,222); CCTintTo *tintto = CCTintTo::create(3,255,255); CCFadeIn *fadein = CCFadeIn::create(3); CCFadeOut *fadeout = CCFadeOut::create(3); CCFadeTo *fadeto = CCFadeTo::create(3,100); CCPointArray *pointarray = CCPointArray::create(6); pointarray->addControlPoint(ccp(100,160)); pointarray->addControlPoint(ccp(200,250)); pointarray->addControlPoint(ccp(300,160)); pointarray->addControlPoint(ccp(450,160)); CCCardinalSplineTo *cardinal = CCCardinalSplineTo::create(10,pointarray,1); CCBlink *blink = CCBlink::create(3,5); CCEaseExponentialIn *exponentin = CCEaseExponentialIn::create(moveby); CCEaseBackIn *bakcin = CCEaseBackIn::create(moveby);
方法好多好多,具体的可以看api,实在不明白的可以根据上面的实例看api,关于一些缓冲可以自己动手做实验,这里我再怎么说也不顶你自己实践一把。
最后还有CCSpeed和CCFollow,CCSpeed主要就是变速嘛:
CCSpeed *speed = CCSpeed::create(moveby,5);//将速度提升5倍
话说CCFollow我也是半吊子,不敢乱说,自己只亲手做了个实验,今天就弄到这里吧
行啦,博主最近要早睡啦,11点前必须睡,晚安啦~
原文链接:https://www.f2er.com/cocos2dx/343612.html