Game Development Reference
In-Depth Information
// Code removed for simplicity
// See chapter source
// ...
}
The class constructor SpaceBlasterGame starts by initializing the Android context by calling
super(context) and setting the game update delay to 40 milliseconds. Note that the context is critical for
all the UI thread operations. A series of Paint objects is also defined to hold the style and color
information about how to draw geometries, text, and bitmaps:
mTextPaint holds style and color information for the text. It will be initialized as
white.
mBitmapPaint holds style and color information for all bitmaps.
mLaserBarPaint holds style and color information for the laser bar at the bottom of
the screen.
mShieldBarPaint holds style and color information for the shield bar at the bottom
of the screen.
mShieldPaint holds style and color information for the ship's shield. It will be used
to draw an oval filled with a semitransparent light blue color around the ship.
Initializing Sprites and Sounds
Game initialization occurs in the initialize method overloaded from the parent abstract class
ArcadeGame (see Listing 3-6). The call sequence goes as follows: LinearLayout.onLayout calls
ArcadeGame.initilize , which calls SpaceBlasterGame.initilize . This last method performs the
following tasks:
Set the screen size.
Set the style and color attributes for the Paint objects: text, laser bar, and shield
bar.
Load the game bitmap sprites: ship, meteor, laser bullet, and explosion sequence.
Load the audio clips.
Listing 3-6. Game Initialization
public void initialize() {
int n;
// Screen size
int width = getWidth();
int height = getHeight();
// Text Paints
mTextPaint.setARGB(255, 255, 255, 255);
mShieldPaint.setARGB(125, 0, 255, 255);
Search WWH ::




Custom Search