GTGE API

com.golden.gamedev.object.background
Class TileBackground

java.lang.Object
  extended by com.golden.gamedev.object.Background
      extended by com.golden.gamedev.object.background.abstraction.AbstractTileBackground
          extended by com.golden.gamedev.object.background.TileBackground
All Implemented Interfaces:
Serializable

public class TileBackground
extends AbstractTileBackground

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);
 

See Also:
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

TileBackground

public TileBackground(BufferedImage[] tileImages,
                      int[][] tiles)
Creates new 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.

Parameters:
tileImages - an array of images for the tile
tiles - a two dimensional array that makes up the background

TileBackground

public TileBackground(BufferedImage[] tileImages,
                      int horiz,
                      int vert)
Creates new 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.

Parameters:
tileImages - an array of images for the tile
horiz - total horizontal tiles
vert - total vertical tiles
Method Detail

renderTile

public void renderTile(Graphics2D g,
                       int tileX,
                       int tileY,
                       int x,
                       int y)
Description copied from class: AbstractTileBackground
Renders tile at tileX, tileY position to specified x, y coordinate.

Specified by:
renderTile in class AbstractTileBackground

getTileImages

public BufferedImage[] getTileImages()
Return the tile background tile images.


setTileImages

public void setTileImages(BufferedImage[] tileImages)
Sets the tile background tile images.


getTiles

public int[][] getTiles()
Returns the background tiling.


setTiles

public void setTiles(int[][] tiles)
Sets the background tiling.

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.

See Also:
setTileImages(BufferedImage[])

setSize

public void setSize(int horiz,
                    int vert)
Description copied from class: AbstractTileBackground
Sets the size of this background (in tiles).

Overrides:
setSize in class AbstractTileBackground
Parameters:
horiz - total background horizontal tiles
vert - total background vertical tiles

GTGE API

Copyright © 2003-2005 Golden T Studios. All rights reserved. Use is subject to license terms.
GoldenStudios.or.id