|
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
public abstract class AbstractTileBackground
The base abstract class to create tiling background, the subclass need to perform the background tile rendering.
renderTile(Graphics2D, int, int, int, int)
,
Serialized FormField Summary |
---|
Fields inherited from class com.golden.gamedev.object.Background |
---|
screen, x, y |
Constructor Summary | |
---|---|
AbstractTileBackground(int horiz,
int vert,
int tileWidth,
int tileHeight)
Creates new AbstractTileBackground as big as
horiz , vert tiles, where each tile is as big as
tileWidth , tileHeight . |
Method Summary | |
---|---|
int |
getOffsetX()
Returns current background tile offset-x. |
int |
getOffsetY()
Returns current background tile offset-y. |
Point |
getTileAt(double screenX,
double screenY)
Returns background tile position of specified coordinate or null if the coordinate is out of background viewport/boundary. |
int |
getTileHeight()
Returns the height of the tile. |
int |
getTileWidth()
Returns the width of the 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 (in tiles). |
void |
setTileLocation(int xs,
int ys)
Sets the background location to specified tile. |
protected void |
setTileSize(int tileWidth,
int tileHeight)
Sets the background tile size. |
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 AbstractTileBackground(int horiz, int vert, int tileWidth, int tileHeight)
AbstractTileBackground
as big as
horiz
, vert
tiles, where each tile is as big as
tileWidth
, tileHeight
.
The actual dimension of the background is :
width = horiz*tileWidth, height = vert*tileHeight.
Method Detail |
---|
public void render(Graphics2D g, int xbg, int ybg, int x, int y, int w, int h)
Background
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.
render
in class Background
g
- graphics contextxbg
- background x-coordinateybg
- background y-coordinatex
- screen start x clippingy
- screen start y clippingw
- clipping widthh
- clipping heightpublic abstract void renderTile(Graphics2D g, int tileX, int tileY, int x, int y)
tileX
, tileY
position to
specified x
, y
coordinate.
public void setLocation(double xb, double yb)
Background
setLocation
in class Background
xb
- the x
coordinate of the backgroundyb
- the y
coordinate of the backgroundpublic void setTileLocation(int xs, int ys)
public int getTileX()
public int getTileY()
public Point getTileAt(double screenX, double screenY)
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 int posX = (tileAt.x - bg.getTileX()) * bg.getTileWidth(), posY = (tileAt.y - bg.getTileY()) * bg.getTileHeight(); g.setColor(Color.WHITE); g.drawRect(posX - bg.getOffsetX() + bg.getClip().x, posY - bg.getOffsetY() + bg.getClip().y, bg.getTileWidth(), bg.getTileHeight()); } } }
public int getOffsetX()
This offset value that makes smooth scrolling on the background tile.
public int getOffsetY()
This offset value that makes smooth scrolling on the background tile.
public int getTileWidth()
public int getTileHeight()
protected void setTileSize(int tileWidth, int tileHeight)
public int getTotalHorizontalTiles()
public int getTotalVerticalTiles()
public void setSize(int horiz, int vert)
setSize
in class Background
horiz
- 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 |