首页 > 代码库 > Cocos2d-x3.0 捕捉Android的菜单键和返回键
Cocos2d-x3.0 捕捉Android的菜单键和返回键
原文地址:http://blog.csdn.net/qqmcy/article/details/26172665
.h
void onKeyReleased(EventKeyboard::KeyCode keycode, Event* event);
.cpp 注册返回键监听
// // PrograssScene.cpp // SJKB // // Created by 杜甲 on 14-5-5. // // #include "PrograssScene.h" #include "VisibleRect.h" bool PrograssScene::init() { bool bRet = false; do { CC_BREAK_IF(!Scene::init()); //注册捕捉监听 auto listenerkeyPad = EventListenerKeyboard::create(); listenerkeyPad->onKeyReleased = CC_CALLBACK_2(PrograssScene::onKeyReleased, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerkeyPad, this); _prograssLayer = PrograssLayer::create(); _prograssLayer->setSize(VisibleRect::getVisibleRect().size); addChild(_prograssLayer); bRet = true; } while (0); return bRet; } //捕捉监听 void PrograssScene::onKeyReleased(EventKeyboard::KeyCode keycode, cocos2d::Event *event) { if (keycode == EventKeyboard::KeyCode::KEY_BACKSPACE) //返回 { Director::getInstance()->popScene(); } else if (keycode == EventKeyboard::KeyCode::KEY_MENU) { } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。