本文介绍了的Andr​​oid后退按钮不起作用在cocos2d-X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要放弃我的Cocos2D-X游戏后退按钮preSS的Andr​​oid系统。为此,我已经超负荷了 CCLayer :: keyBackClicked 在我的类方法 GameScene ,我也叫 setKeypadEnabled(真) GameScene ::初始化。但是, keyBackClicked 方法不会被调用时,pressing后退按钮,我已经检查了 CCLOG 信息。还有什么我需要做的,使这项工作?我搜索了很多关于这个话题,发现上面的解决方案,但它不工作。

I want quit my Cocos2d-x game on back button press in Android. For this I have overloaded the CCLayer::keyBackClicked method in my class GameScene and I have also called setKeypadEnabled(true) from GameScene::init. However, the keyBackClicked method is never called when pressing the back button, I have checked with a CCLog message. What else do I have to do to make this work? I have searched a lot on this topic and found the above solution but it's not working.

下面是我的code

bool GameScene:: init() {
    if(CCLayer::init()) {
        CCLog("Init");
        this->setKeypadEnabled(true);
        return true;
    }
    return false;
}

void GameScene:: keyBackClicked(void) {
    CCLayer::keyBackClicked();
    CCLOG("cclayer key back clicked");
    exit(0);
}

请帮忙。

推荐答案

CCLayer添加代理功能中的OnEnter()函数调用,您可能需要调用 CCLayer ::的OnEnter GameScene ::的OnEnter()或也许你需要在其他地方添加。

CCLayer add the delegate function in the onEnter() function call,you may need call CCLayer::onEnter in GameScene::onEnter() or maybe you need add it elsewhere.

CCLayer::onEnter
//
...
    if (m_bKeypadEnabled)
    {
        pDirector->getKeypadDispatcher()->addDelegate(this);
    }
//
...

这篇关于的Andr​​oid后退按钮不起作用在cocos2d-X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 04:08