Cocos2d-x 3.x android平臺選單返回鍵監聽

nmjkl發表於2015-03-09

android平臺選單返回鍵監聽

//宣告

void onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event);

//實現

//按鍵控制(檢測onKeyReleased有反應)
auto listener = EventListenerKeyboard::create();
listener->onKeyReleased = CC_CALLBACK_2(MenuLayer::onKeyReleased, this);
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
void MenuLayer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
    switch(keyCode)
    {
    //監聽返回鍵
    case EventKeyboard::KeyCode::KEY_ESCAPE:

         Director::getInstance()->end();
        break;
    //監聽menu鍵
    case EventKeyboard::KeyCode::KEY_MENU:
        break;
    }
} 

相關文章