How do I callback a function when label is touched in cocos2d-x?
1 Answer
you can't set a callback function for CCLabelTTF
or any other Label class, yet there is CCMenuItemLabel you can use.
you first need to create an instance of CCMenu
class. then you need to allocate CCMenuItemLabel
instance, using CCMenuItem::initWithLabel (CCNode *label, CCObject *target, SEL_MenuHandler selector)
. just check how helloworld sample handled it, although it's using CCMenuItemImage, but the base idea is just same in both.