I used to bind method in cocos2d-x 2.1 with:
element->setTarget(this, (cocos2d::SEL_MenuHandler) (&MainMenu::NewGame));
What is the alternative(s) for set parent and bind method in cocos2d-x 3.0?
I used to bind method in cocos2d-x 2.1 with:
element->setTarget(this, (cocos2d::SEL_MenuHandler) (&MainMenu::NewGame));
What is the alternative(s) for set parent and bind method in cocos2d-x 3.0?
In v2.x you were supposed to call it like this:
element-\>setTarget(this, menu\_selector(&MainMenu::NewGame));
Have you tried doing this in v3?
That example couldn’t work without
using namespace cocos2d;
My example work, but I wish to implement non-deprecate method. and setTarget isn’t that.
P.S. Maybe I should change title to setTarget instead SEL_MenuHandler
Which type is element?
MenuItemSprite
CC_DEPRECATED_ATTRIBUTE void setTarget (Object *rec, SEL_MenuHandler selector)
http://www.cocos2d-x.org/reference/native-cpp/d7/da9/classcocos2d_1_1_menu_item.html
From the official Release Note :
http://cocos2d-x.org/projects/cocos2d-x/wiki/Release_Node_v300#stdfunction
From the official Release Note :
http://cocos2d-x.org/projects/cocos2d-x/wiki/Release_Node_v300#stdfunction
Sorry for late response…
So, 3.0 solution for targeting MenuItem is:
element->setCallback(std::bind(&MainMenu::NewGame, this, std::placeholders::_1));
Thank you!