1. Mobile button monitoring
OGE provides the onkeyup and onkeydown methods defined in basegamelauncher (the parent class of gamelauncher) and iscene (the interface implemented by scene) so that developers can listen to mobile buttons, ogekeyevent provides a variety of Button tags that can be used to determine the button tags generated by keycode. Return Boolean indicates whether the event has been processed. If it is false, it indicates that the event has not been processed and is passed to another onkeydown. (Refer to Android event handling mechanism)
@ Override
Public Boolean onkeydown (INT keycode ){
If (keycode = ogekeyevent. keycode_back ){
// End the game
Getengine (). finishgame ();
Return true;
}
Return super. onkeydown (keycode );
}
2. game suspension and Restoration
The current version has encapsulated onresumegame and onpausegame. When basegamelauncher is executed in the lifecycle, the engine is automatically started or stopped. Therefore, in onresumegame and onpausegame, you only need to pause the playing of music and sound, and then switch to the android desktop and re-enter the game.
[V2.x OGE tutorial 19] Engine status control