【发布时间】:2014-07-25 20:03:12
【问题描述】:
我这样做是为了在 android 设备上捕获 Home 和 Back 按钮按下事件:
重写void Layer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event) 函数如下:
void MyLayer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
if (keyCode == EventKeyboard::KeyCode::KEY_BACKSPACE /*KeyboardEvent::KeyCode::Menu(KEY_BACKSPACE)*/)
{
CCLOG("You pressed back button");
Director::getInstance()->end();
exit(0);
}
else if (keyCode == EventKeyboard::KeyCode::KEY_HOME)
{
CCLOG("You pressed home button");
// pause the game
}
}
在MyLayer的init函数中也调用了setKeypadEnabled(true);。 Backspace 按钮在 Windows 上关闭游戏,但在 Home 按钮上没有反应。同样在 Android 上,当我按下 Home 或 Back 时,什么也没有发生。如何让它在 cocos2d-x 3.1 上运行?
【问题讨论】:
-
您不能在 android 中覆盖主页按钮操作。
标签: android c++ cocos2d-x cocos2d-x-3.0