Reputation: 68
I used following code to add listener method to a Button in cocos2dx:
button->addTouchEventListener(this, toucheventselector(HomeScene::doSomething));
But since Cocos2dx 3.1 both toucheventselector and addTouchEventListener is depreciated. There is :
void addTouchEventListener(ccWidgetTouchCallback callback);
I can't make it work - I tried every macro I could find - callfuncO_selector, CC_CALLBACK etc. I just don't know how to point to my method that looks like this:
void HomeScene::doSomething(Ref *pSender, Widget::TouchEventType type);
Failed to find any clue from Google, forum, git, change log, tests...
Upvotes: 4
Views: 10813
Reputation: 13
You can also use this:
button->addTouchEventListener(CC_CALLBACK_2(HomeScene::doSomething,this));
to solve this issue :-)
Upvotes: 0
Reputation: 1029
Well, I usually subclass my button and add listeners to it. Example: http://cocos2d-x.org/wiki/How_To_Subclass_Sprite_And_Add_Event_Listeners
Upvotes: 1