cocos2d-x 3.2 android返回键退出

来源:互联网 发布:阿里云解析 编辑:程序博客网 时间:2024/04/28 07:04

添加如下代码:


auto listener = EventListenerKeyboard::create();

listener->onKeyReleased = CC_CALLBACK_2(HelloWorld::onKeyReleased, this);


auto dispatcher = Director::getInstance()->getEventDispatcher();

dispatcher->addEventListenerWithFixedPriority(listener, -1);



void HelloWorld::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.", "Alert");
    return;
#endif

    Director::getInstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}

0 0
原创粉丝点击