Game Development Reference
In-Depth Information
Loading Bitmap Sprites
Bitmap sprites are loaded by SpaceBlasterGame.initialize from the drawables section of the project
using the getImage(RESOURCEID) method. getImage is defined in the base class ArcadeGame , so it'll be easy
for child classes to reuse. For example, the game's explosion is simply an array of bitmaps loaded from
the drawables folder (shown in Figure 3-5). To create an explosion, the game manipulates the explosion
frame number when the display is drawn. The tricky part is keeping track of many explosions and their X
and Y coordinates. Consider the next fragment, which loads bitmaps for the ship, laser bullet and
explosion frames:
// Ship
ship = getImage(R.drawable.sb_ship);
// Laser Bullet
bullet = getImage(R.drawable.sb_bullet);
// Load meteor explosion sequence sprites
ids = new int[] { R.drawable.sb_boom0, R.drawable.sb_boom1,
R.drawable.sb_boom2, R.drawable.sb_boom3,
R.drawable.sb_boom4 };
boom = new Bitmap[bframes + 1];
for (n = 0; n <= bframes; n++) {
boom[n] = getImage(ids[n]);
}
Search WWH ::




Custom Search