public void setViewWindow(int x, int y, int width, int height) – Sets the portion of the PlayField that will be drawn when draw(Graphics, int, int) is called. This will limit the portion of the PlayField that is drawn to the rectangle defined by the region (x, y) to (x + width, y + height). The default view window (at construction time) is the entire area of the PlayField, i.e. the rectangular region bounded by (0, 0) and (getGridWidth() * getCellWidth(), getGridHeight() * getCellHeight()).The rectangle defined by the parameters may extend beyond the bounds of the PlayField. If this happens, the draw(graphics, int, int) method will draw no tiles in the area outside the grid boundaries. Sprites may still be drawn in this area if their position places them outside the bounds of the PlayField grid. The view window stays in effect until it is modified by another call to this method or is reset as a result of calling setStaticTileSet(Image, int, int). The method parameters are x - x coord of top-left pixel for the drawing view window, y - y coord of top-left pixel for the drawing view window, width - width of the drawing view window, and height - height of the drawing view window.

Using PlayField

The following is a code sample to show implementation of PlayField:

PlayField

//Creates a playField with 100 columns and 10

//rows and tiles with 24x16 pixels

PlayField foreground = new PlayField(100, 10,

Image.createImage("tiles.png"), 24, 16);

//Sets the first cell in the first line to

//empty(tile with index 0) foreground.setCell(0, 0, 0);

//Fills the second cell in the first line with tile 1 foreground.setCell(1, 0, 1);

//Fills the third cell in the first line with tile 2 foreground.setCell(2, 0, 2);

//Fills the fourth cell in the first line with tile 3 foreground.setCell(3, 0, 3);

//Gets the Graphics object for this GameScreen Graphics g = getGraphics();

//Draws the foreground playfield

foreground.draw(g, 0, 0);

Page 54
Image 54
Motorola C550, C450, C370 technical manual Using PlayField