I measured the back button of Android, which was not acquired in Cocos2d-js.
(It may be that Cocos2d-js has intercepted Android's fallback, so native Java code is useless),
No way can only use Cocos2d-js's own realization:
One, prepare a back image
Second, add the event to monitor the back button:
//Back Button Press two times to exit the gameCc.eventManager.addListener ({event:cc. Eventlistener.keyboard, onkeyreleased:function(KeyCode, event) {if(KeyCode = = cc.) Key.back) {//Beta version The back of the KeyCode error, you can also change to 6Cc.log ("return button clicked. KeyCode: "+keycode); That.exitby2click (); } Else if(KeyCode = = cc.) Key.menu) {//The beta version of the menu here is keycode wrong and can be changed toCc.log ("menu button clicked. KeyCode: "+keycode); } }}, This);
Third, add function exitby2click()
isexit:false,//Global Variables
exitlogo:null,//Global Variables
Exitby2click:function(){ if( This. Isexit = =false) { This. Isexit =true;//Ready to Exit //If the return key is not pressed within 2 seconds, the start timer cancels out the task just performed This. Exitlogo =Newcc. Sprite (res.exitlogo_png); This. Exitlogo.setposition (Cc.padd (Cc.visibleRect.bottom, CC.P (0, 120))); This. AddChild ( This. Exitlogo, 10); varArrowaction = Cc.sequence (Cc.fadeout (2), Cc.callfunc (function () { This. Isexit =false; }, This)); This. Exitlogo.runaction (arrowaction); } Else{cc.director.end (); } }
COCOS2D-JS implementation Double-click the Android Back button to exit the game