我必须将目标c ++转换为C ++ 11.我坚持使用以下语法。 我在testcpp中引用并尝试以下语法。
这里是我尝试的代码:
this->runAction
(
Sequence::create
(
blink,
CallFunc::create(CC_CALLBACK_0(Hero::stopBlinking, NULL)), -> issue this line.
NULL
)
);
显示错误"no matching function for call to 'bind'" in "CallFunc::create".
任何人都可以帮助或帮助我。
答案 0 :(得分:8)
在您的编码中,只需替换以下代码:
CallFuncN::create(CC_CALLBACK_1(Hero::stopBlinking,this));
由于
CallFunc can be created with an @std::function<void()>
CallFuncN can be created with an @std::function<void(Node*)
参见:
http://www.cocos2d-x.org/wiki/Release_Notes_for_Cocos2d-x_v300/diff/5
答案 1 :(得分:2)
由于我遇到同样的问题,这可能对某人有所帮助
CallFunc::create( std::bind(&Hero::stopBlinking,this) );
答案 2 :(得分:1)
您需要执行以下操作
FiniteTimeAction *callAct = CallFunc::create(CC_CALLBACK_0(Hero::stopBlinking, this));
Sequence* seq = Sequence::create(blink,callAct ,NULL);
this->runAction(seq);
答案 3 :(得分:1)
通过lambda函数的另一种方法:
CallFuncN *callFunc = CallFuncN::create([&] (Node* node) {
// cast node to Hero and do what you need with it
});
但当然,这更适合短代码块:
node->removeFromParent();