|
GTGE API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.golden.gamedev.object.Background
com.golden.gamedev.object.background.abstraction.AbstractTileBackground
com.golden.gamedev.object.background.TileBackground
public class TileBackground
The basic tiling background, creates a one layer background tile.
TileBackground takes up two parameter, the first one is a two
dimensional array of integer (int[][] tiles) that makes up the background
tiling, and the second one is the tiling image array
(BufferedImage[] tileImages).
This tile background is the basic subclass of
AbstractTileBackground that overrides renderTile
method to draw one layer tile background :
public void render(Graphics2D g, int tileX, int tileY, int x, int y) {
// tiles is the two dimensional background tiling
int tile = tiles[tileX][tileY];
if (tile >= 0) {
// tileImages is the tiling images
g.drawImage(tileImages[tile], x, y, null);
}
}
To create multiple layer, simply subclass AbstractTileBackground
and override the renderTile method to render the tile multiple
times. Tile background usage example :
TileBackground background;
BufferedImage[] tileImages;
int[][] tiles = new int[40][30]; // 40 x 30 tiling
// fill tiles with random value
for (int i=0;i < tiles.length;i++)
for (int j=0;j < tiles[0].length;j++)
tiles[i][j] = getRandom(0, tileImages.length-1);
// create the background
background = new TileBackground(tileImages, tiles);
AbstractTileBackground,
Serialized Form| Field Summary |
|---|
| Fields inherited from class com.golden.gamedev.object.Background |
|---|
screen, x, y |
| Constructor Summary | |
|---|---|
TileBackground(BufferedImage[] tileImages,
int[][] tiles)
Creates new TileBackground with specified tile images
and array of tiles. |
|
TileBackground(BufferedImage[] tileImages,
int horiz,
int vert)
Creates new TileBackground with specified tile images, as
big as horiz, vert tiles. |
|
| Method Summary | |
|---|---|
BufferedImage[] |
getTileImages()
Return the tile background tile images. |
int[][] |
getTiles()
Returns the background tiling. |
void |
renderTile(Graphics2D g,
int tileX,
int tileY,
int x,
int y)
Renders tile at tileX, tileY position to
specified x, y coordinate. |
void |
setSize(int horiz,
int vert)
Sets the size of this background (in tiles). |
void |
setTileImages(BufferedImage[] tileImages)
Sets the tile background tile images. |
void |
setTiles(int[][] tiles)
Sets the background tiling. |
| Methods inherited from class com.golden.gamedev.object.background.abstraction.AbstractTileBackground |
|---|
getOffsetX, getOffsetY, getTileAt, getTileHeight, getTileWidth, getTileX, getTileY, getTotalHorizontalTiles, getTotalVerticalTiles, render, setLocation, setTileLocation, setTileSize |
| Methods inherited from class com.golden.gamedev.object.Background |
|---|
getClip, getDefaultBackground, getHeight, getWidth, getX, getY, move, render, setClip, setClip, setToCenter, setToCenter, update |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TileBackground(BufferedImage[] tileImages,
int[][] tiles)
TileBackground with specified tile images
and array of tiles. The array of tiles that makes up the background tiling, tiles[0][0] = 2 means the tileImages[2] will be drawn on tile 0, 0 coordinate on the map.
tileImages - an array of images for the tiletiles - a two dimensional array that makes up the background
public TileBackground(BufferedImage[] tileImages,
int horiz,
int vert)
TileBackground with specified tile images, as
big as horiz, vert tiles. Generates tile background with tile as big as horiz and vert (tiles = new int[horiz][vert]) and using the first image of the tile images (tileImages[0]) for all the tiles.
tileImages - an array of images for the tilehoriz - total horizontal tilesvert - total vertical tiles| Method Detail |
|---|
public void renderTile(Graphics2D g,
int tileX,
int tileY,
int x,
int y)
AbstractTileBackgroundtileX, tileY position to
specified x, y coordinate.
renderTile in class AbstractTileBackgroundpublic BufferedImage[] getTileImages()
public void setTileImages(BufferedImage[] tileImages)
public int[][] getTiles()
public void setTiles(int[][] tiles)
This array of tiles that makes up the background tiling, tiles[0][0] = 2 means the tileImages[2] will be drawn on tile 0, 0 coordinate on the map.
setTileImages(BufferedImage[])
public void setSize(int horiz,
int vert)
AbstractTileBackground
setSize in class AbstractTileBackgroundhoriz - total background horizontal tilesvert - total background vertical tiles
|
GTGE API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||