COCO2D-JS/COCOS2D-HTML5 in Android back key implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.