Cocos2d-x:在callfuncN_selector中添加参数
Cocos2d-x: add parameter in callfuncN_selector
我想为精灵运行如下动作:
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时,你可以传递节点和数据作为参数,但我认为选项与标签更简单:)
相关文章:
- 可变参数模板与使用元组在参数中添加不同的数据对
- 如何在OMNET++中添加专门的命令行参数?
- 如何将带有参数的愚蠢函数添加到愚蠢的执行器中?
- 为模板参数包添加别名
- 如何使用主参数添加更多堆栈?
- C++中添加参数的沙漏
- 为什么在函数参数前面添加 const 会出错?
- 为什么我们需要在优先级队列声明中添加一个向量作为参数?
- 具有可变参数包的模板化可添加类
- 添加可变参数函数的错误结果
- 在对象序列化期间添加额外参数是否有更好的方法?
- 在C++中,如何将参数添加到"Args&&... args"参数列表中?
- C++添加检查以避免读取两个参数
- 如何添加参数-Fvisibility =默认为cmake
- 我可以为模板类的模板类型添加参数吗?
- 添加参数后"模板参数推断/替换失败"
- 添加参数或添加函数
- Cocos2d-x:在callfuncN_selector中添加参数
- 我想创建一个std::函数,但增量地添加参数
- 向前向声明的模板添加参数