Java Reference
In-Depth Information
TiledLayer
The abstract
Layer
class is the parent class of
TiledLayer
and
Sprite
.
A
TiledLayer
consists of a grid of cells each of which can be filled
with an image tile. An instance of
TiledLayer
is created by invoking
the constructor:
public TiledLayer(int columns, int rows, Image image, int tileWidth,
int tileHeight);
The
columns
and
rows
arguments represent the number of columns
and rows in the grid. The
tileWidth
and
tileHeight
arguments
represent the width and height of a single tile in pixels. The
image
argument represents the image used to create the set of tiles that populate
the
TiledLayer
. Naturally, the dimension of the image in pixels must
be an integral multiple of the dimension of an individual tile. The use of
TiledLayer
is best illustrated with an example.
One of the principal uses of
TiledLayer
is the creation of large
scrolling backgrounds from relatively few tiles. Consider the example
in Figure 2.6, which shows a big set of tiles of equal dimensions that
we can arrange in different ways to create a
TiledLayer
background
using selected tiles. You can for example reuse tile 1 to create a large
lake or tiles 1, 5 and 16 to create a strip of land surrounded by a small
Figure 2.6
Image for use by a
TiledLayer