我想为如下 Sprite 运行 Action :
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 中使用您的值。当您的操作被调用时,您可以简单地从发件人的标签中获取您的值(value)。
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,但我认为带有标签的选项更简单:)
关于c++ - Cocos2d-x: 在callfuncN_selector中添加参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25450261/