Reputation: 5685
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);
Upvotes: 1
Views: 1389
Reputation: 587
For simple CCCallFunc callbacks that take no parameters, you may want to check out MCBCallLambda.
Upvotes: 2
Reputation: 1592
It is possible for any method that accepts CCCallFunc [1] or its subclasses. Create own subclass of CCCallFunc which keeps std::function and overrides execute method and maybe some other methods (figure out which implementation needed from CCCallFunc sources).
[1] http://www.cocos2d-x.org/embedded/cocos2d-x/dd/d6e/classcocos2d_1_1_c_c_call_func.html
Upvotes: 0
Reputation: 1824
I don't think it's possible. The way they are called by Cocos2d-x is by using a target pointer to a CCObject
in combination with a method pointer. Thus, the target has to be a CCObject
. As you said, these are defined for different types of parameters. Cocos2d-x need to be changed to support this.
Upvotes: 0