(1).在.h文件中加入
void onKeyReleased(EventKeyboard::KeyCode keycode,Event* event);//返回键调用方法
void Movement::onKeyReleased(EventKeyboard::KeyCode keycode,cocos2d::Event *event)
{
Director::getInstance()->end();
}
//创建监听事件
auto listenerkeyPad = EventListenerKeyboard::create();
//将被监听的方法写到监听里面去
listenerkeyPad->onKeyReleased = CC_CALLBACK_2(Movement::onKeyReleased,this);
//添加监听(_eventDispatcher 来自node)
_eventDispatcher->addEventListenerWithSceneGraPHPriority(listenerkeyPad,this);
就这样Android返回键的功能就完成了
原文链接:https://www.f2er.com/cocos2dx/345503.html