本文介绍了Android设备返回键和home键pressed事件(的cocos2d-X 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经这样做了追赶首页返回 Android设备上的按钮preSS事件:

I have done this to catch Home and Back buttons press events on android devices:

Overrided 无效层:: onKeyReleased(EventKeyboard ::主要code键code,事件*事件)函数是这样的:

Overrided void Layer::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event) function like this:

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

还要求 setKeypadEnabled(真); 的init 功能 MyLayer 。退格键关闭Windows上的游戏,但在首页键无反应。同时在Android上没有任何反应,当我preSS主页或后退。如何得到这个工作的cocos2d-X 3.1?

also have called setKeypadEnabled(true); in init function of MyLayer. Backspace button closes the game on windows, but no reaction on Home button. Also on Android nothing happens when I press Home or Back. How to get this working on cocos2d-x 3.1?

推荐答案

有关捕后退按钮,你需要使用 EventKeyboard ::重点code :: KEY_ESCAPE 。对于暂停游戏的时候家是pressed使用无效的AppDelegate :: applicationDidEnterBackground()。有没有办法覆盖home键按下事件。

For catching Back button you need to use EventKeyboard::KeyCode::KEY_ESCAPE. For pausing the game when Home is pressed use void AppDelegate::applicationDidEnterBackground(). There is no way to override home button pushed event.

这篇关于Android设备返回键和home键pressed事件(的cocos2d-X 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 04:58