4

我必须将目标 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". 任何人都可以帮助或帮助我。

4

4 回答 4

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

于 2014-01-20T06:19:21.627 回答
2

由于我遇到了同样的问题,它可能会帮助某人

CallFunc::create( std::bind(&Hero::stopBlinking,this) );
于 2014-05-10T14:20:45.377 回答
1

您需要执行以下操作

    FiniteTimeAction *callAct = CallFunc::create(CC_CALLBACK_0(Hero::stopBlinking, this));
    Sequence* seq = Sequence::create(blink,callAct ,NULL);
    this->runAction(seq);
于 2015-03-19T11:23:06.927 回答
1

通过 lambda 函数的另一种方法:

CallFuncN *callFunc = CallFuncN::create([&] (Node* node) {
    // cast node to Hero and do what you need with it
});

但是当然,这更适合短代码块,例如:

node->removeFromParent();
于 2017-03-15T07:20:40.417 回答