Android back button exits game

// android back press event
auto touchListener = EventListenerKeyboard::create();
touchListener->onKeyReleased = [](cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event *event)
{
    if (keyCode == EventKeyboard::KeyCode::KEY_BACK)
    {
        Director::getInstance()->end();
    }
};
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

Just add this to any node/layer/scene

3 Likes