Android平台菜单返回键监听

Android平台菜单返回键监听

函数声明

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

添加监听

1
2
auto listener =vEventListenerKeyboard::create();
listener->onKeyReleased = CC_CALLBACK_2(MenuLayer::onKeyReleased,this);

函数实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//退出游戏
void MenuLayer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
switch(keyCode)
{ //监听返回键
case EventKeyboard::KeyCode::KEY_ESCAPE:
{
CocosDenshion::SimpleAudioEngine::sharedEngine()->end();
Director::getInstance()->end();
exit(0);
}
//监听menu键
case EventKeyboard::KeyCode::KEY_MENU:
break;
}
}
文章目录
  1. 1. 函数声明
  2. 2. 添加监听
  3. 3. 函数实现
,