Introductory Remarks:First of all, cocos2d-x the menu and Back buttons are relatively simple, but in the cocos2d-html5 of resources less. There is a bit of a difference in whether to return or not, and there is no detailed demo. You just have to see the API documentation for yourself. This is also a headache thing, summarized below and summarized in COCOS2D-HTML5. How to implement the return key. and the menu key.
Analysis:in cocos2d, only layer and its subclasses can get user input right now. The event that triggered the user input.
The conclusion is that I've pushed through the API documentation to trigger these events. There must be setiskeypadenabled and setistouchenabled methods, and there are only layers and subclasses in the API that have these two methods, so it is very natural to implement the return in the layer scene or its subclasses.
Code:
Mylayer.backclicked=function () {Cc.log ("Back Clicked");Cc. Audioengine.getinstance (). Stopalleffects ();Cc. Builderreader.runscene ("", "Levellayer");}Mylayer. setkeypadenabled (True);
Note: This method is only suitable for use with Cocoseditord. Version number after cocos2d-js3.0 please use the following codeCc.eventManager.addListener ({event:cc. Eventlistener.keyboard,onkeyreleased:function (KeyCode, event) {if (keycode = = cc. Key.back) {}else if (keycode = = cc. Key.menu) { }}} , this); Cc.eventManager.addCustomListener (Cc.game.EVENT_HIDE, function () {//onenterbackground Handler});Cc.eventManager.addCustomListener (Cc.game.EVENT_SHOW, function () {//onenterforeground Handler});
|
COCO2D-JS/COCOS2D-HTML5 in Android back key implementation