Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I callback a function when label is touched in cocos2d-x?

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
Thanks HelloWorld sample tip really helped ! :) – 2600th Mar 19 '12 at 8:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.