GTGE API

com.golden.gamedev.object.background.abstraction
Class AbstractIsometricBackground

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

public abstract class AbstractIsometricBackground
extends Background

The base abstract class to create isometric background, the subclass need to perform the background tile rendering.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.golden.gamedev.object.Background
screen, x, y
 
Constructor Summary
AbstractIsometricBackground(int horiz, int vert, int tileWidth, int tileHeight)
          Creates new AbstractIsometricBackground as big as horiz, vert tiles, where each tile is as big as tileWidth, tileHeight.
AbstractIsometricBackground(int horiz, int vert, int tileWidth, int tileHeight, int offsetTileHeight, int startY)
          Creates new AbstractIsometricBackground as big as horiz, vert tiles, where each tile is as big as tileWidth, tileHeight with specified tile height offset, and starting y coordinate.
 
Method Summary
 Point getCoordinateAt(int tileX, int tileY)
          Returns screen coordinate of specified tile position.
 int getOffsetTileHeight()
          Returns the tile height offset from the base tile height.
 int getStartY()
          Returns starting y coordinate where the isometric background start rendered.
 Point getTileAt(double screenX, double screenY)
          Returns iso tile position of specified coordinate or null if the coordinate is out of background viewport/boundary.
 int getTileHeight()
          Returns the base height of the iso tile.
 int getTileWidth()
          Returns the width of the iso tile.
 int getTileX()
          Returns current tile-x position.
 int getTileY()
          Returns current tile-y position.
 int getTotalHorizontalTiles()
          Returns background total horizontal tiles.
 int getTotalVerticalTiles()
          Returns background total vertical tiles.
 void render(Graphics2D g, int xbg, int ybg, int x, int y, int w, int h)
          Renders background from specified position and clipping area to specified graphics context.
abstract  void renderTile(Graphics2D g, int tileX, int tileY, int x, int y)
          Renders tile at tileX, tileY position to specified x, y coordinate.
 void setLocation(double xb, double yb)
          Sets background location to specified coordinate.
 void setSize(int horiz, int vert)
          Sets the size of this background.
 void setStartY(int startY)
          Sets starting y coordinate where the isometric background start rendered.
 void setTileLocation(int xs, int ys)
          Sets the background location to specified tile.
protected  void setTileSize(int tileWidth, int tileHeight, int offsetTileHeight)
          Sets the size of the iso tile.
 
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

AbstractIsometricBackground

public AbstractIsometricBackground(int horiz,
                                   int vert,
                                   int tileWidth,
                                   int tileHeight,
                                   int offsetTileHeight,
                                   int startY)
Creates new AbstractIsometricBackground as big as horiz, vert tiles, where each tile is as big as tileWidth, tileHeight with specified tile height offset, and starting y coordinate.

Parameters:
horiz - total horizontal tiles
vert - total vertical tiles
tileWidth - the width of the iso tile
tileHeight - the height of the iso tile
offsetTileHeight - the tile height offset from the base tile height
startY - starting y coordinate to draw this background

AbstractIsometricBackground

public AbstractIsometricBackground(int horiz,
                                   int vert,
                                   int tileWidth,
                                   int tileHeight)
Creates new AbstractIsometricBackground as big as horiz, vert tiles, where each tile is as big as tileWidth, tileHeight.

Parameters:
horiz - total horizontal tiles
vert - total vertical tiles
tileWidth - the width of the iso tile
tileHeight - the height of the iso tile
Method Detail

render

public void render(Graphics2D g,
                   int xbg,
                   int ybg,
                   int x,
                   int y,
                   int w,
                   int h)
Description copied from class: Background
Renders background from specified position and clipping area to specified graphics context.

This method to simplify background subclass rendering, the subclass only need to render the background from specified x, y coordinate with specified clipping area.

For example:

    Background backgr;
    Graphics2D g;

    backgr.render(g, 100, 100,
                  5, 10, 100, 200);
 
Means the background must render itself from background coordinate 100, 100 to specified graphics context, starting from 5, 10 screen pixel as large as 100 x 200 dimension.

Overrides:
render in class Background
Parameters:
g - graphics context
xbg - background x-coordinate
ybg - background y-coordinate
x - screen start x clipping
y - screen start y clipping
w - clipping width
h - clipping height

renderTile

public abstract void renderTile(Graphics2D g,
                                int tileX,
                                int tileY,
                                int x,
                                int y)
Renders tile at tileX, tileY position to specified x, y coordinate.


setLocation

public void setLocation(double xb,
                        double yb)
Description copied from class: Background
Sets background location to specified coordinate. The location is bounded to background boundary (0, 0, Background.getWidth(), Background.getHeight()).

Overrides:
setLocation in class Background
Parameters:
xb - the x coordinate of the background
yb - the y coordinate of the background

setTileLocation

public void setTileLocation(int xs,
                            int ys)
Sets the background location to specified tile.


getTileX

public int getTileX()
Returns current tile-x position.


getTileY

public int getTileY()
Returns current tile-y position.


getTileAt

public Point getTileAt(double screenX,
                       double screenY)
Returns iso tile position of specified coordinate or null if the coordinate is out of background viewport/boundary. Used to detect mouse position on this background, for example :
Drawing rectangle at mouse cursor position
    public class YourGame extends Game {

       AbstractTileBackground bg;

       public void render(Graphics2D g) {
          Point tileAt = bg.getTileAt(getMouseX(), getMouseY());

          if (tileAt != null) {
             // mouse cursor is in background area
             // draw pointed tile

             // convert tile to coordinate
             Point coordAt = bg.getCoordinateAt(tileAt.x, tileAt.y);

             g.setColor(Color.WHITE);
             g.drawRect(coordAt.x - (int) bg.getX() + bg.getClip().x,
                        coordAt.y - (int) bg.getY() + bg.getClip().y,
                        bg.getTileWidth(), bg.getTileHeight());
          }
       }

    }
 


getCoordinateAt

public Point getCoordinateAt(int tileX,
                             int tileY)
Returns screen coordinate of specified tile position. Can be used in conjunction with getTileAt(double, double) to get tile coordinate at specified coordinate.


getTileWidth

public int getTileWidth()
Returns the width of the iso tile.


getTileHeight

public int getTileHeight()
Returns the base height of the iso tile.

This is the base height of the isometric tile, the actual image tile is getTileHeight() + getOffsetTileHeight().

See Also:
getOffsetTileHeight()

getOffsetTileHeight

public int getOffsetTileHeight()
Returns the tile height offset from the base tile height.


setTileSize

protected void setTileSize(int tileWidth,
                           int tileHeight,
                           int offsetTileHeight)
Sets the size of the iso tile.

Parameters:
tileWidth - the width of the iso tile
tileHeight - the height of the iso tile
offsetTileHeight - the tile height offset from the base tile height

getStartY

public int getStartY()
Returns starting y coordinate where the isometric background start rendered.


setStartY

public void setStartY(int startY)
Sets starting y coordinate where the isometric background start rendered.


getTotalHorizontalTiles

public int getTotalHorizontalTiles()
Returns background total horizontal tiles.


getTotalVerticalTiles

public int getTotalVerticalTiles()
Returns background total vertical tiles.


setSize

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

Overrides:
setSize in class Background

GTGE API

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