扩展动作CCCallFunc、CCCallFuncN、CCCallFuncND和CCCallFuncO区别

扩展动作(复习一下,呵呵,健忘微笑)
函数
   在动作序列中间或者末尾调用某个函数,执行任何任务:动作、状态修改等。在cocos2d-x中,调用函数的动作一共有4种。


   1.CCCallFunc 仅函数调用,无任何参数。


voidExtendActionLayer::onCallBack1()
{
    flight->runAction(CCTintBy::actionWithDuration(0.5f,255,0,255));
}

voidExtendActionLayer::onCallFunc(CCObject* pSender)
{
    CCFiniteTimeAction *action1 = CCMoveBy::actionWithDuration(2.0f, ccp(200,200));
    CCFiniteTimeAction *action2 = action1->reverse();
    CCFiniteTimeAction *actionF = CCCallFunc::actionWithTarget(this, callfunc_selector(ExtendActionLayer::onCallBack1));
    flight->runAction(CCSequence::actions(action1, actionF, action2, NULL));
}


2.CCCallFuncN


调用函数,并将当前对象的指针(CCNode指针)作为第一个参数传递进去。


voidExtendActionLayer::onCallBack2(CCNode* pSender)
{
//在这个例子里,pSender就是flight,因为是他执行了那个actionF
pSender->runAction(CCTintBy::actionWithDuration(1.0f,255,0,255));
}

voidExtendActionLayer::onCallFuncN(CCObject* pSender)
{
CCFiniteTimeAction *action1 = CCMoveBy::actionWithDuration(2.0f, ccp(200,200));
CCFiniteTimeAction *action2 = action1->reverse();
CCFiniteTimeAction *actionF = CCCallFuncN::actionWithTarget(this, callfuncN_selector(ExtendActionLayer::onCallBack2));
flight->runAction(CCSequence::actions(action1, actionF, action2, NULL));

}


3.CCCallFuncND

在前一种方式的基础上增加一个数据参数,这是void指针类型。


voidExtendActionLayer::onCallBack3(CCNode* pSender,void* pData)
{
pSender->runAction(CCTintBy::actionWithDuration(static_cast<float>((int)pData),255,0,255));
}

voidExtendActionLayer::onCallFuncND(CCObject* pSender)
{
CCFiniteTimeAction *action1 = CCMoveBy::actionWithDuration(2.0f, ccp(200,200));
CCFiniteTimeAction *action2 = action1->reverse();
//这里直接将整数常量强转成(void *)类型似乎有欠妥当,但对这些Action的生命周期不太清楚,稍后深入一下。
CCFiniteTimeAction *actionF = CCCallFuncND::actionWithTarget(this, callfuncND_selector(ExtendActionLayer::onCallBack3), (void*)2);
flight->runAction(CCSequence::actions(action1, actionF, action2, NULL));

}


4.CCCallFuncO

调用函数,并传递一个CCObject指针作为参数。这个似乎不太常用,资料比较少,以后再深入。

你可能感兴趣的:(扩展动作CCCallFunc、CCCallFuncN、CCCallFuncND和CCCallFuncO区别)