1
缓冲动作
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" >
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" >
man->setScale(0.8f); woman->setScale(0.8f); man->setPosition(ccp(100, 80)); woman->setPosition(ccp(100,240)); |
CCMoveTo * manTo = CCMoveTo::create(2, ccp(400,80)); CCMoveTo * womanTo = CCMoveTo::create(2, ccp(400, 240)); CCEaseExponentialIn *in = CCEaseExponentialIn::create(manTo); CCEaseExponentialOut *out = CCEaseExponentialOut::create(manTo); CCEaseExponentialInOut * inOut = CCEaseExponentialInOut::create(manTo); man->runAction(inOut); woman->runAction(womanTo); |
CCEaseElasticIn *in = CCEaseElasticIn::create(manTo); CCEaseElasticOut *out = CCEaseElasticOut::create(manTo); CCEaseElasticInOut * inOut = CCEaseElasticInOut::create(manTo); |
#include "T13Action.h" #include CCScene *T13Action::scene() { CCScene * T13Action * scene->addChild(layer); return } bool { TBack::init(); CCSprite * CCSprite * man->setPosition(ccp(100, CCMoveBy *by CCMoveBy CCEaseExponentialIn * in = CCEaseExponentialInOut CCEaseExponentialInOut * //CCEaseElasticIn * in = CCEaseElasticIn::create(by2); //CCEaseElasticOut * out = CCEaseElasticOut::create(by2); //CCEaseElasticInOut * inOut = CCEaseElasticInOut::create(by2); //CCEaseBounceIn //CCEaseBounceOut * out = CCEaseBounceOut::create(by2); //CCEaseBounceInOut * inOut = CCEaseBounceInOut::create(by2); //看精灵的执行速度 //man->runAction(in); //man->runAction(out); man->runAction(inOut); addChild(man); return } //原生画图,每一帧都会画图 void { CCPointArray *array = array->addControlPoint(ccp(100, array->addControlPoint(ccp(200, array->addControlPoint(ccp(200, array->addControlPoint(ccp(300, array->addControlPoint(ccp(300, array->addControlPoint(ccp(450, ccDrawCardinalSpline(array, 1, 100); } |
执行结果: |
2
并行动作和序列动作
CCSequence
中持续时间为全部动作累计的总合。CCSequence
中不能够
有CCRepeatForever
动作。
CCSpwan中持续时间为并行动作持续时间最长的决定。
3
假动作
CCCallFunc系列动作包含CCallFunc()、CCCallFuncN()、CCCallFuncND,以及CCCallFuncO四个动作,CCCallFunc系列动作的后缀”N”表示Node參数,指的是运行动作的对象,”D”表示Data參数,指的是用户自己定义的数据。”O”表示对象,指的是一个用户自己定义的CCObject參数。
在不同的情况下。我们能够依据不同的需求来选择不同的CCCallFunc动作。
typedef void (CCObject::*SEL_CallFunc)(); |
//无參类型 typedef void (CCObject::*SEL_CallFuncN)(CCNode*); //传递CCNode * typedef void (CCObject::*SEL_CallFuncND)(CCNode*, void*); //传递CCNode * typedef void (CCObject::*SEL_CallFuncO)(CCObject*); //传递CCObject *类型变量 #define callfunc_selector(_SELECTOR) (SEL_CallFunc)(&_SELECTOR) #define callfuncN_selector(_SELECTOR) (SEL_CallFuncN)(&_SELECTOR) #define callfuncND_selector(_SELECTOR) (SEL_CallFuncND)(&_SELECTOR) #define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR) |
CCCallFunc * func = CCCallFunc::create(this, callfunc_selector(T13Action::funcCallBack)); CCCallFuncN * func = CCCallFuncN::create(this, callfuncN_selector(T13Action::funcNCallBack)); CCCallFuncND * func = CCCallFuncND::create(this, callfuncND_selector(T13Action::funcNDCallBack), (void *)"30"); CCArray * array = CCArray::create(); array->addObject(woman); CCCallFuncO * func = CCCallFuncO::create(this, callfuncO_selector(T13Action::funcOCallBack),(CCObject*)array); CCSequence * seq = CCSequence::create(to, func, NULL); man->runAction(seq); addChild(man); |
案例说明:
无參的假动作 void |
T13Action.h |
#ifndef _T13Action_H__ #define #include #include USING_NS_CC; class { public: static CREATE_FUNC(T13Action); bool void //无參的假动作 void //带调用者的假动作 void //带有调用者和数据的假动作 void //带有对象的假动作 void }; #endif |
T13Action.cpp |
#include "T13Action.h" #include CCScene *T13Action::scene() { CCScene * T13Action * scene->addChild(layer); return } bool { TBack::init(); CCSprite * CCSprite * man->setPosition(ccp(100, CCMoveBy *by2 //假动作就是当一个动作运行完了之后又运行的一个动作 CCCallFunc * CCSequence * man->runAction(seq); addChild(man); return } //原生画图。每一帧都会画图 void { CCPointArray *array = array->addControlPoint(ccp(100, array->addControlPoint(ccp(200, array->addControlPoint(ccp(200, array->addControlPoint(ccp(300, array->addControlPoint(ccp(300, array->addControlPoint(ccp(450, ccDrawCardinalSpline(array, 1, 100); } //无參的假动作 void CCLog("action } |
执行结果(执行速度是变速的): 输出结果: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdG90b3R1enVvcXVhbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" > |
4
假动作
#ifndef _T13Action_H__ #define #include #include USING_NS_CC; class { public: static CREATE_FUNC(T13Action); bool //无參的假动作 void //带调用者的假动作 void //带有调用者和数据的假动作 void //带有对象的假动作 void }; #endif |
#include "T13Action.h" #include CCScene *T13Action::scene() { CCScene * T13Action * scene->addChild(layer); return } bool { TBack::init(); CCSprite * CCSprite * man->setPosition(ccp(50, woman->setPosition(ccp(50,260)); //创建一个CCArray,在使用前调用retain(),要注意的是在最后退出之 //后要在onExit()中将array进行release() CCArray * array = array->retain(); array->addObject(woman); CCMoveBy *by2 CCCallFuncN * callfuncN_selector(T13Action::funcNCallBack)); //调用 CCCallFuncND *funcND callfuncND_selector(T13Action::funcNDCallBack), (void*)"30"); CCCallFuncO callfuncO_selector(T13Action::funcOCallBack), array); CCSequence * man->runAction(seq); addChild(man); return } //当中CCNode表示的是动作的运行者 void { CCSprite *spr //将精灵从屏幕上 //spr->removeFromParentAndCleanup(true); CCJumpBy * spr->runAction(by); } void { CCSprite *spr //以下是取出数据的代码 CCString * //给精灵旋转 spr->setRotation(str->floatValue()); } void { CCArray * array = (CCArray*)obj; //从array中取出第0个元素 CCSprite * addChild(spr); } |