cocos2d-x之JS中的Android按键监听

找个layer节点添加如下代码即可,啦啦啦啦

<span style="white-space:pre">	</span>//Android返回键监听
        cc.eventManager.addListener({
            event: cc.EventListener.KEYBOARD,
            onKeyReleased: function(keyCode, event) {
                if (keyCode == cc.KEY.back) {    
                    cc.log("return button clicked. keycode:" + keyCode);
                    if(GameVariable.isGamePlay){
                        uiManager.mainLayer.showLayer(layerId.game_main_exit, layerZOrder.game_main_exit);
                    }else{
                        GameVariable.exit4MM();
                    }
                }
                else if (keyCode == cc.KEY.menu) {    
                    cc.log("menu button clicked. keycode:" + keyCode);
                }
            }}, this);


        //进入后台
        cc.eventManager.addCustomListener(cc.game.EVENT_HIDE, function(){
            //
        });


        //恢复显示
        cc.eventManager.addCustomListener(cc.game.EVENT_SHOW, function(){
            //
        });


你可能感兴趣的:(android,cocos2d-x,按键监听)