Java Reference
In-Depth Information
Figure 8-2. The three tiles shown in (a) make up the tile image shown in (b), which is used
repeatedly to create the tiled region in shown in (c).
As you can see in Figure 8-2(a), each tile must have the same width and height.
You can combine these tiles in a number of ways, as shown in the strip in Figure 8-2(b),
so that each tile makes up one portion of an Image object. Finally, you can use multiple
tiles in succession to create a larger image—such as a game background—as you see in
Figure 8-2(c).
The TiledLayer class takes an image consisting of unique tiles, such as that shown in
Figure 8-2(b), and a set of indexes you provide into the Image object, and fills the cells of
an image with the tiles at each index. These indexes begin with the number 1 , indicating
the tile at the upper-left corner of the image, and increment working left to right and top
to bottom across the image you provide.
For example, you can compose Figure 8-2(c) using the Image in Figure 8-2(b) and the
indexes into that image in Listing 8-4.
Listing 8-4. The Array of Indexes into the Tiles That Form the Image
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 1, 1, 1, 1, 1,
1, 1, 1, 1, 3, 1, 1, 1,
1, 2, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 2, 1,
1, 1, 1, 3, 1, 1, 1, 1,
1, 1, 1, 1, 1, 3, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1
Each cell of a TiledLayer image can either be a single tile in the source bitmap or be
transparent, letting the layers behind the TiledLayer show through.
 
Search WWH ::




Custom Search