Game Development Reference
In-Depth Information
Figure 4-4.
The Asteroids resources
Understanding the Game Life Cycle
As mentioned earlier, we use a
LinerLayout
to paint sprites on screen using a continuous game loop. The
layout and loop—both controlled using
Timer
s—are described by the abstract class
ArcadeGame
(see
Listing 4-5). This class also defines the life cycle of the game using abstract methods that must be
overridden by the child class
Asteroids
. This life cycle contains the following methods:
void initialize()
fires on game initialization. This is where sounds are loaded
and sprites are created.
•
void onDraw()
must be overridden to paint sprites on screen. All painting is done
using a
Canvas
and one or more
Paint
objects for font, color, and style
information.
•