This article briefly introduces the program architecture of the mobile game engine of j2's mobile phone. In Game Development and any software design, a stable engine structure must be established as the basic architecture of software design, it is the core supporting framework of the software architecture.
Program architecture of the mobile game engine based on
In game development and any software design, a stable engine structure must be established as the basic architecture of software design. It is the core supporting framework of the software architecture, all functions are implemented and extended in this infrastructure. The design of a game involves game control, roles, game scenarios, items, game sound effects, game process event listening mechanisms, and other elements, therefore, a good game engine can effectively control the above elements. This article introduces the basic program architecture of the game engine in the design of the game with the help of the j2_m3-based architecture.
The game engine can be implemented by establishing different structures, but any game design is inseparable from the design of a master loop to repeatedly control the entire game process, of course, the core structure of the game (background phantom control, Genie coordinate change, action frame screen change, etc.) is included in this loop. In the design of a j2-based game, two core classes are required for the program architecture, namely, MIDlet and Displayable.
1. The MIDlet is the main class of j2's. Any program master class must inherit the MIDlet to control the entire game lifecycle. It must cover the three cycle methods in the MIDlet: startApp, pauseApp, and destoryApp, the operation body of the start, pause, and end actions.
- Public class Game Testextends MIDlet
- Implements CommandListener {
- /**
- * Game engine Introduction
- */
- PrivateCommandexitCommand;
- PrivateGameCanvasTestgameCanvas;
- PublicGameTest (){
- ExitCommand = newCommand ("exit ?, Command. exit, 1 );
- GameCanvasTestgameCanvas = newGameCanvasTest (this );
- Sfcan. addCommand (exitCommand );
- Sfcan. setCommandListener (this );
- Display. getDisplay (this). setCurrent (gameCanvas );
- // TODO automatically generates the constructor stub
- }
- ProtectedvoidstartApp ()
- ThrowsMIDletStateChangeException {
- // TODO automatically generates method stubs
- // GameCanvas. thread. start ();
- }
- ProtectedvoidpauseApp (){
- // TODO automatically generates method stubs
- Try {
- GameCanvas. thread. wait ();
- } Catch (effectione ){}
- }
- ProtectedvoiddestroyApp (booleanarg0)
- ThrowsMIDletStateChangeException {
- // TODO automatically generates method stubs
- GameCanvas = null;
- }
- PublicvoidcommandAction (Commandc, Displayabled ){
- If (c = exitCommand ){
- Yydestroyed ();
- }
- }
- // Implement scheduling of game process interface changes and different operations
- PublicvoidchangeTale (inttaleIndex)
- {
- Code Implementation .......
- Display. getDisplay (this). setCurrent (....);
- }
- }
The GameTest class inherits the MIDlet class to control the game lifecycle, and only controls the game lifecycle and the UI scheduling in the game process, the specific core game modules are implemented in the GameCanvasTest class.