I don’t know if I’m doing something wrong or if I don’t understand some concept here; but I had a problem with buttons (they didn’t respond) and it was because there were a virtual void onEnter() on the class.
Here is the relevant code:
Header
public:
virtual bool init();
private:
virtual void onEnter(); // if I delete this, button works fine.
virtual void onExit();
void onMenuDn(CCObject* sender);
CCMenuItemSprite* menu_btn;
CCMenu* menu;
Implementation
bool Class::init()
{
CCSprite* spriteOn = .....;
CCSprite* spriteOff = .....;
menu_btn = CCMenuItemSprite::create(spriteOff, spriteOn, this, menu_selector(Class::onMenuDn));
menu = CCMenu::create(menu_btn, NULL);
return true;
}
void Class::onEnter()
{
......
}
void Class::onMenuDn(CCObject* sender)
{
CCLog("Button pressed");
}
With onEnter() the button doesn’t work, but if take out the onEnter method the button works fine. Why is this happening? Is this a bug? or am I missing something?
Cocos version: cocos2d-x-2.2
Thanks!