How to call callfunc function in cocos2dx 3.0

让人想犯罪 __ 提交于 2019-12-12 11:47:40

问题


I have to convert objective c++ to C++ 11. I have stuck with the following syntax. I have referred in testcpp and try the following syntax.

Here the code which i tried:

this->runAction
(
 Sequence::create
 (
  blink,
  CallFunc::create(CC_CALLBACK_0(Hero::stopBlinking, NULL)),    -> issue this line.
  NULL
  )
 );

It shows error "no matching function for call to 'bind'" in "CallFunc::create". Can any one assist or help me.


回答1:


In your coding, just replace the below code:

 CallFuncN::create(CC_CALLBACK_1(Hero::stopBlinking,this));

Because

 CallFunc can be created with an @std::function<void()>  
 CallFuncN can be created with an @std::function<void(Node*)

Refer:

http://www.cocos2d-x.org/wiki/Release_Notes_for_Cocos2d-x_v300/diff/5




回答2:


Since I was having the same problem, it might help someone

CallFunc::create( std::bind(&Hero::stopBlinking,this) );



回答3:


You need to do the following

    FiniteTimeAction *callAct = CallFunc::create(CC_CALLBACK_0(Hero::stopBlinking, this));
    Sequence* seq = Sequence::create(blink,callAct ,NULL);
    this->runAction(seq);



回答4:


One more way via lambda functions:

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

But of course, this is more suitable for short code block like:

node->removeFromParent();


来源:https://stackoverflow.com/questions/21215804/how-to-call-callfunc-function-in-cocos2dx-3-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!