Cocos2d-x:在callfuncN_selector中添加参数

Cocos2d-x: add parameter in callfuncN_selector

本文关键字:添加 参数 selector callfuncN Cocos2d-x      更新时间:2023-10-16

我想为精灵运行如下动作:

CCRotateTo* actionTo = CCRotateTo::create(0.2, 0.0f, -90.0f);
CCRotateTo* actionToBack = CCRotateTo::create(0.2, 0.0f, -180.0f);
CCFiniteTimeAction* actionChangeTexture = CCCallFuncN::create(this,
    callfuncN_selector(Paddle::spriteChangeTextture));**//*i want to send value here***
runAction(CCSequence::create(actionTo,actionChangeTexture,actionToBack, NULL));

void Paddle::spriteChangeTextture(CCNode* sender) {
  ***//i want to using parameter here, it's integer value***
}

如何在函数调用中发送值。请帮助

您可以在CCNode中使用标记。在节点setTag中使用您的值。当你的动作被调用时,你可以简单地从发送者的标签中获取你的值。

CCRotateTo* actionTo = CCRotateTo::create(0.2, 0.0f, -90.0f);
CCRotateTo* actionToBack = CCRotateTo::create(0.2, 0.0f, -180.0f);
CCFiniteTimeAction* actionChangeTexture = CCCallFuncN::create(this,
    callfuncN_selector(Paddle::spriteChangeTextture));
int value;
setTag(value); // <-------- 
runAction(CCSequence::create(actionTo,actionChangeTexture,actionToBack, NULL));

void Paddle::spriteChangeTextture(CCNode* sender) {
int value = sender->getTag; // <------------
}

另一个选项是使用CCCallFuncND时,你可以传递节点和数据作为参数,但我认为选项与标签更简单:)