void callBack();void callBack_1(Node* node);void callBack_2(Node* node,const char* str);void Nice::callBack(){log("Nice::callBack()");}void Nice::callBack_1(Node* node){log("This tag is %d",node->getTag());}void Nice::callBack_2(Node* node,const char* str){log("This tag is %d, and str is %s",node->getTag(), str);}//然后就開始創(chuàng)建我們偉大的精靈了。sp_area = Sprite::create("newAlwaysShow.png");//sp_area is a class member ,Sprite* ap_area;sp_area->setTag(1314);auto sp_another = Sprite::create();sp_another->setTag(520);addChild(sp_another);addChild(sp_area);//翻滾吧。可愛的精靈們!/*CallFunc 創(chuàng)建的函數(shù)必須是無參數(shù)的CallFuncN 創(chuàng)建的函數(shù)能夠是一個(gè)至多個(gè)參數(shù)*/sp_area->runAction(Sequence::create(MoveTo::create(2, Vec2(200, 200)),CallFunc::create(CC_CALLBACK_0(Nice::callBack, this)),CallFuncN::create(CC_CALLBACK_1(Nice::callBack_2, this, "I have tow parameter")),NULL));//這樣寫完之后。發(fā)現(xiàn)runAction里面的東西好平淡(平淡有時(shí)候才不是真呢!
),于是我就瞎寫一通。殘忍的把它變成了這個(gè)樣子。 sp_area->runAction(Sequence::create(MoveTo::create(2, Vec2(200, 200)), CallFunc::create(CC_CALLBACK_0(Nice::callBack, this)), CallFunc::create([&]()->void{log("Done1");log("This tag is %d", sp_area->getTag());}), CallFunc::create(std::bind(&Nice::callBack, this)), CallFuncN::create(CC_CALLBACK_1(Nice::callBack_1, this)),//1314 CallFuncN::create(CC_CALLBACK_0(Nice::callBack_1, this, sp_another)),//520 CallFuncN::create([](Node* node){log("this tag is %d", node->getTag());}),//1314 CallFuncN::create(std::bind(&Nice::callBack_1, this, sp_area)),//1314 CallFuncN::create(std::bind(&Nice::callBack_1, this, sp_another)),//520 CallFuncN::create(CC_CALLBACK_1(Nice::callBack_2, this, "I have tow parameter")), NULL));
Sequece::create是分平臺(tái)實(shí)現(xiàn)的(分為win和其它)#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)// WP8 in VS2012 does not support nullptr in variable args lists and variadic templates are also not supportedtypedef FiniteTimeAction* M;static Sequence* create(M m1, std::nullptr_t listEnd) { return variadicCreate(m1, NULL); }static Sequence* create(M m1, M m2, std::nullptr_t listEnd) { return variadicCreate(m1, m2, NULL); }static Sequence* create(M m1, M m2, M m3, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, NULL); }static Sequence* create(M m1, M m2, M m3, M m4, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, NULL); }static Sequence* create(M m1, M m2, M m3, M m4, M m5, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, NULL); }static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, NULL); }static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, NULL); }static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, NULL); }static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, NULL); }static Sequence* create(M m1, M m2, M m3, M m4, M m5, M m6, M m7, M m8, M m9, M m10, std::nullptr_t listEnd) { return variadicCreate(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, NULL); }// On WP8 for variable argument lists longer than 10 items, use the other create functions or variadicCreate with NULL as the last argumentstatic Sequence* variadicCreate(FiniteTimeAction* item, ...);
#elsestatic Sequence* create(FiniteTimeAction *action1, ...) CC_REQUIRES_NULL_TERMINATION;
#endifSequence* Sequence::create(FiniteTimeAction *action1, ...)
{va_list params;va_start(params, action1);Sequence *ret = Sequence::createWithVariableList(action1, params);//傳給了createWithVariableList讓他來處理va_end(params);return ret;
}Sequence* Sequence::createWithVariableList(FiniteTimeAction *action1, va_list args)
{FiniteTimeAction *now;FiniteTimeAction *prev = action1;bool bOneAction = true;while (action1){now = va_arg(args, FiniteTimeAction*);//假設(shè)第二個(gè)動(dòng)作存在if (now){prev = createWithTwoActions(prev, now);bOneAction = false;}//假設(shè)第二個(gè)動(dòng)作不存在else{// If only one action is added to Sequence, make up a Sequence by adding a simplest finite time action.if (bOneAction){prev = createWithTwoActions(prev, ExtraAction::create());}break;}}return ((Sequence*)prev);
} 我們就依照他的思路來實(shí)現(xiàn)一個(gè)可變參數(shù)的函數(shù)