Search code examples
c++11cocos2d-x

cocos2d-x write the callbacks using c++11 lambda


sometimes the usage of a callback is very limited, which makes it in-appropriate to be a member function. so at these times I always want to write the event call backs as lambda functions as the usage is limited the codeblock is compact if wrote in lambda

but this callback is generally defined member functions and there are interface limitations inforced on it

I wonder if it is possbile to rewrite the callback in lambda functions ?

 pMenuOK->setTarget(this,menu_selector(PlayerLayer::onPlayed));
 void PlayerLayer::onPlayed(cocos2d::CCObject *pSender);

Solution

  • For simple CCCallFunc callbacks that take no parameters, you may want to check out MCBCallLambda.