Motorola C450 User Manual

Page of 86

Gaming API and Sound  
 
49 
calling 
setAnimatedTileImage(-2, 2);
, cells (0,0) and (0,1) will then be drawn 
with the image of static Tile 2. 
Using Sprites 
In addition to being a grid of cells, a 
Playfield
 can have a set of associated 
Sprites
 
(see 0 item). When the 
PlayField
 is drawn, the grid is considered to have depth 0. 
Therefore, 
Sprites
 below the grid (
Sprites
 with 
Sprite.getDepth() < 0
are drawn first. Then all cells in the grid are drawn. Then all the 
Sprites
 above the grid 
(
Sprite.getDepth() >= 0
) are drawn. The 
Sprites
 are drawn according to 
their location and visibility status as defined in the 
Sprite
 class. The location of 
Sprites
 is relative to the top-left corner of the 
PlayField
Defining View Windows 
A view window onto the 
PlayField
 can be defined using the method 
setViewWindow()
. This defines the area of the 
PlayField
 that will be drawn by 
the 
draw()
 method. The default viewing window onto a 
PlayField
 (at construction 
time) is the entire area of the 
PlayField
.  
PlayField Constructor 
The 
PlayField
 class defines the following constructors: 
PlayField (int columns, int rows, Image img, int tWidth, int tHeight) throws 
NullPointerException, IllegalArgumentException - Creates a new PlayField with a tile 
set. The parameter are the following
:   
− 
columns
 - width of the PlayField in number of cells; 
− 
rows
 - height of the PlayField in number of cells; 
− 
img
 - Image to use for creating tiles; 
− 
tWidth
 - width, in pixels, of the individual tiles; 
− 
tHeight
 - height, in pixels, of the individual tiles. 
It creates a new 
PlayField
rows
 cells high and 
columns
 cells wide. The static 
tile set for the PlayField will be created from subsections of the image passed in. The 
PlayField
 grid is initially filled with empty cells (tile 0 - a reserved tile and 
represents an empty square) and laying out tiles must be accomplished through the 
use of other methods in the class. The creation of the static tile set follows these 
standards: 
Tiles must be equally sized, all being of the tile width (
tWidth
) and height 
(
tHeight
) defined in the constructor parameters. They may be laid out in the image 
horizontally, vertically, or as a grid. The width of the source image must be an integer