码迷,mamicode.com
首页 > 移动开发 > 详细

Cocos2d-x3.0 捕捉Android的菜单键和返回键

时间:2014-05-22 10:01:21      阅读:310      评论:0      收藏:0      [点我收藏+]

标签: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)
    {
        
    }
}


Cocos2d-x3.0 捕捉Android的菜单键和返回键,布布扣,bubuko.com

Cocos2d-x3.0 捕捉Android的菜单键和返回键

标签:cocos2d-x3.0   android   返回   监听   

原文地址:http://blog.csdn.net/qqmcy/article/details/26172665

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!