Cocos2d-x 3.x android平台菜单返回键监听

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; } } 

你可能感兴趣的:(Android开发,cocos2d-x,android平台)