Program architecture of the mobile game engine of j2's mobile phone (1)

Source: Internet
Author: User

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.

 
 
  1. Public class Game Testextends MIDlet
  2. Implements CommandListener {
  3. /**
  4. * Game engine Introduction
  5. */
  6. PrivateCommandexitCommand;
  7. PrivateGameCanvasTestgameCanvas;
  8. PublicGameTest (){
  9. ExitCommand = newCommand ("exit ?, Command. exit, 1 );
  10. GameCanvasTestgameCanvas = newGameCanvasTest (this );
  11. Sfcan. addCommand (exitCommand );
  12. Sfcan. setCommandListener (this );
  13. Display. getDisplay (this). setCurrent (gameCanvas );
  14. // TODO automatically generates the constructor stub
  15. }
  16. ProtectedvoidstartApp ()
  17. ThrowsMIDletStateChangeException {
  18. // TODO automatically generates method stubs
  19. // GameCanvas. thread. start ();
  20. }
  21. ProtectedvoidpauseApp (){
  22. // TODO automatically generates method stubs
  23. Try {
  24. GameCanvas. thread. wait ();
  25. } Catch (effectione ){}
  26. }
  27. ProtectedvoiddestroyApp (booleanarg0)
  28. ThrowsMIDletStateChangeException {
  29. // TODO automatically generates method stubs
  30. GameCanvas = null;
  31. }
  32. PublicvoidcommandAction (Commandc, Displayabled ){
  33. If (c = exitCommand ){
  34. Yydestroyed ();
  35. }
  36. }
  37. // Implement scheduling of game process interface changes and different operations
  38. PublicvoidchangeTale (inttaleIndex)
  39. {
  40. Code Implementation .......
  41. Display. getDisplay (this). setCurrent (....);
  42. }
  43. }

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.


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.