GTGE API

com.golden.gamedev.object.background
Class IsometricBackground

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

public class IsometricBackground
extends AbstractIsometricBackground

The basic isometric background, creates a one layer isometric background.

IsometricBackground 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 isometric background is the basic subclass of AbstractIsometricBackground that overrides renderTile method to draw one layer isometric 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 AbstractIsometricBackground and override the renderTile method to render the tile multiple times.

Isometric background usage example :

    IsometricBackground  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 IsometricBackground(tileImages, tiles);
 

See Also:
AbstractIsometricBackground, Serialized Form

Field Summary
 
Fields inherited from class com.golden.gamedev.object.Background
screen, x, y
 
Constructor Summary
IsometricBackground(BufferedImage[] tileImages, int[][] tiles)
          Creates new IsometricBackground with specified tile images and array of tiles.
IsometricBackground(BufferedImage[] tileImages, int[][] tiles, int offsetTileHeight, int startY)
          Creates new IsometricBackground with specified tile images, array of tiles, offset of tile height, and starting y coordinate.
IsometricBackground(BufferedImage[] tileImages, int horiz, int vert)
          Creates new IsometricBackground with specified tile images as big as horiz and vert tiles.
 
Method Summary
 BufferedImage[] getTileImages()
          Return the isometric background tile images.
 int[][] getTiles()
          Returns the isometric 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.
 void setTileImages(BufferedImage[] tileImages, int offsetTileHeight)
          Sets the isometric background tile images.
 void setTiles(int[][] tiles)
          Sets the isometric background tiling.
 
Methods inherited from class com.golden.gamedev.object.background.abstraction.AbstractIsometricBackground
getCoordinateAt, getOffsetTileHeight, getStartY, getTileAt, getTileHeight, getTileWidth, getTileX, getTileY, getTotalHorizontalTiles, getTotalVerticalTiles, render, setLocation, setStartY, 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

IsometricBackground

public IsometricBackground(BufferedImage[] tileImages,
                           int[][] tiles,
                           int offsetTileHeight,
                           int startY)
Creates new IsometricBackground with specified tile images, array of tiles, offset of tile height, and starting y coordinate.

The array of tiles that makes up the isometric background tiling, tiles[0][0] = 2 means the tileImages[2] will be drawn on tile 0, 0 coordinate on the map.

The offsetTileHeight is used to determine the tile image base tile height, for example the real height of the tile image is 128 but the base height of the tile image is 32, therefore set the offsetTileHeight to 96 (128-32).

The startY is where the isometric background y coordinate is starting to render, set this startY value greater than zero if this background need to be drawn down a bit.

Parameters:
tileImages - an array of images for the tile
tiles - a two dimensional array that makes up the background
offsetTileHeight - the tile height offset from the base tile height
startY - starting y coordinate to draw this background

IsometricBackground

public IsometricBackground(BufferedImage[] tileImages,
                           int[][] tiles)
Creates new IsometricBackground with specified tile images and array of tiles.

The array of tiles that makes up the isometric 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

IsometricBackground

public IsometricBackground(BufferedImage[] tileImages,
                           int horiz,
                           int vert)
Creates new IsometricBackground with specified tile images as big as horiz and vert tiles.

Generates isometric 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: AbstractIsometricBackground
Renders tile at tileX, tileY position to specified x, y coordinate.

Specified by:
renderTile in class AbstractIsometricBackground

getTileImages

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


setTileImages

public void setTileImages(BufferedImage[] tileImages,
                          int offsetTileHeight)
Sets the isometric background tile images.


getTiles

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


setTiles

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

This array of tiles that makes up the background, tiles[0][0] = 2 means the tileImages[2] will be drawn on tile 0, 0 coordinate on the map.

See Also:
setTileImages(BufferedImage[], int)

setSize

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

Overrides:
setSize in class AbstractIsometricBackground

GTGE API

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