1.cocos_helloworld

class HelloWorld : public cocos2d::Layer中添加函数

void menuclose(cocos2d::Ref *psender);

实现:

1 void HelloWorld::menuclose(cocos2d::Ref *psender)
2 {
3     Director::getInstance()->end();
4 }

bool HelloWorld::init()中与按钮关联起来

1 auto close = static_cast<ui::Button *> (rootNode->getChildByName("Button_1"));
2     close->addTouchEventListener(CC_CALLBACK_1(HelloWorld::menuclose,this));

截图:

原文地址:https://www.cnblogs.com/xiaochi/p/8302101.html