J2ME Game Development: Issues and Troubleshooting.(TM) -Life Cycle of a Game
by Massimo Perrone ( Hanami Solutions)
3.0 Life Cycle of a Game
Now that we've examinated main problems around compatibility between these devices we will develop our software on, let's take a look in outline at what will be the typical life cycle of our game.
The example given will be based upon Fight, a game that appeared in the USA thanks
to AT&T and in Italy by way of TIM. The screen shots featured in this article belong
to B/W and color versions of the game.
The game itself is a classic one-on-one beat-em-up where two fighters challenge each
other on an horizontal ring. Both the main character and the villains he will face
move and interact with each other.
3.1 How to build a structure to handle such a game?
First of all one must bear in mind that a MIDlet (and so our game is) during its
life cycle pass thru three main states:
start;
eventual pauses;
distruction;
All the code related to these three states will reside inside their corresponding
MIDlet methods, namely: startApp() pauseApp() destroyApp()
Usually first one takes care of hardware initialization, to create an instance of
the display to show the program on and handle all the drawing operations received from
an instance of the Canvas class.
Inside the pauseApp() method, we will show the options menu and allow thus to change
game settings, read instructions and so on.
Last but no least the destroyApp() method will be in charge of setting the resources
free, remove unused objects from game, shut down the application and give back
control of the hardware to the residing operating system.
It can be easily understood that, while pause and destruction methods are quite similar
between all games, content of startApp() method is the real core of the MIDlet and
handles all key operations of the game by mean of the Canvas class and her internal
methods. Amongst them the following are worth being mentioned: paint() method to
draw onscreen everytime currently used frame, keyPressed() and keyReleased() used to
handle pressure and release of the keys and run(), most vital of them, synchronizing
all operations of the game.
Next Page >>
|