【问题标题】:Back and Home buttons pressed event for Android devices (cocos2d-x 3)Android 设备的返回和主页按钮按下事件 (cocos2d-x 3)
【发布时间】:2014-07-25 20:03:12
【问题描述】:

我这样做是为了在 android 设备上捕获 HomeBack 按钮按下事件:

重写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
    }
}

MyLayerinit函数中也调用了setKeypadEnabled(true);。 Backspace 按钮在 Windows 上关闭游戏,但在 Home 按钮上没有反应。同样在 Android 上,当我按下 Home 或 Back 时,什么也没有发生。如何让它在 cocos2d-x 3.1 上运行?

【问题讨论】:

  • 您不能在 android 中覆盖主页按钮操作。

标签: android c++ cocos2d-x cocos2d-x-3.0


【解决方案1】:

要捕获返回按钮,您需要使用EventKeyboard::KeyCode::KEY_ESCAPE。要在按下 Home 时暂停游戏,请使用 void AppDelegate::applicationDidEnterBackground()。无法覆盖主页按钮推送事件。

【讨论】:

    【解决方案2】:

    您可以使用EventKeyboard::KeyCode::KEY_BACKEventKeyboard::KeyCode::KEY_ESCAPE 来捕获Android 后退按钮事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      • 2012-10-28
      • 1970-01-01
      • 2018-08-12
      • 2016-04-04
      • 2013-07-26
      • 1970-01-01
      相关资源
      最近更新 更多