GTGE API

com.golden.gamedev.object
Class Background

java.lang.Object
  extended by com.golden.gamedev.object.Background
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AbstractIsometricBackground, AbstractTileBackground, ColorBackground, ImageBackground, ParallaxBackground

public class Background
extends Object
implements Serializable

Background is the area where every sprites lived.

A background has a view area/view port/clipping area, that is the area which is seen to the player. By default the view area of a newly created background is as big as game dimension. For example if the game is created as big as 640 x 480 dimension, the background view area would be also 640 x 480, thus occupy all the game view. To set the background view area, use setClip(x, y, width, height).

If the background size is larger than view area, means there is area not viewable, use move(dx, dy) or setLocation(double, double) to move around.

To set a sprite to be the center of the background, use setToCenter(Sprite).

See Also:
com.golden.gamedev.object.background, Serialized Form

Field Summary
static Dimension screen
          Screen resolution dimension.
protected  double x
          Background x coordinate.
protected  double y
          Background y coordinate.
 
Constructor Summary
Background()
          Creates new Background, with size and clipping area as large as screen size.
Background(int w, int h)
          Creates new Background with specified size, and default clipping area (as large as screen size).
 
Method Summary
 Rectangle getClip()
          Returns background screen viewport (clipping area), anything outside viewport area will not be rendered.
static Background getDefaultBackground()
          Returns the default background used by every newly created sprite.
 int getHeight()
          Returns the height of this background.
 int getWidth()
          Returns the width of this background.
 double getX()
          Returns the x coordinate of this background.
 double getY()
          Returns the y coordinate of this background.
 void move(double dx, double dy)
          Moves background location by specified pixels.
 void render(Graphics2D g)
          Renders background to specified graphics context.
 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.
 void setClip(int x, int y, int width, int height)
          Sets background clipping area (viewport).
 void setClip(Rectangle r)
          Sets background clipping area (viewport).
 void setLocation(double xb, double yb)
          Sets background location to specified coordinate.
 void setSize(int w, int h)
          Sets the size of this background.
 void setToCenter(int x, int y, int w, int h)
          Sets specified rectangle as the center of the background's viewport.
 void setToCenter(Sprite centered)
          Sets specified sprite as the center of the background's viewport.
 void update(long elapsedTime)
          Updates this background, this method is usually used to create background animation or other special effect on the background.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

screen

public static Dimension screen
Screen resolution dimension. Used to determine background clipping area.
Default value: 640x480.

See Also:
setClip(int, int, int, int)

x

protected double x
Background x coordinate.

See Also:
setLocation(double, double)

y

protected double y
Background y coordinate.

See Also:
setLocation(double, double)
Constructor Detail

Background

public Background(int w,
                  int h)
Creates new Background with specified size, and default clipping area (as large as screen size).

Clipping area is the viewport of the background, anything outside viewport area will not be rendered.

Parameters:
w - background width
h - background height

Background

public Background()
Creates new Background, with size and clipping area as large as screen size.

Clipping area is the view port of the background, anything outside clipping area will not be rendered.

Method Detail

getDefaultBackground

public static Background getDefaultBackground()
Returns the default background used by every newly created sprite.


getX

public double getX()
Returns the x coordinate of this background.


getY

public double getY()
Returns the y coordinate of this background.


getWidth

public int getWidth()
Returns the width of this background.


getHeight

public int getHeight()
Returns the height of this background.


setSize

public void setSize(int w,
                    int h)
Sets the size of this background.


setLocation

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

Parameters:
xb - the x coordinate of the background
yb - the y coordinate of the background

move

public void move(double dx,
                 double dy)
Moves background location by specified pixels.


setToCenter

public void setToCenter(int x,
                        int y,
                        int w,
                        int h)
Sets specified rectangle as the center of the background's viewport.


setToCenter

public void setToCenter(Sprite centered)
Sets specified sprite as the center of the background's viewport.


setClip

public void setClip(int x,
                    int y,
                    int width,
                    int height)
Sets background clipping area (viewport). Clipping area is the viewport of the background, anything outside viewport area will not be rendered.

By default background viewport is as large as screen size.

See Also:
screen

setClip

public void setClip(Rectangle r)
Sets background clipping area (viewport). Clipping area is the viewport of the background, anything outside viewport area will not be rendered.

By default background viewport is as large as screen size.

See Also:
screen

getClip

public Rectangle getClip()
Returns background screen viewport (clipping area), anything outside viewport area will not be rendered.


update

public void update(long elapsedTime)
Updates this background, this method is usually used to create background animation or other special effect on the background.

The implementation of this method provided by the Background class does nothing.


render

public void render(Graphics2D g)
Renders background to specified graphics context.

Parameters:
g - graphics context

render

public 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.

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.

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

GTGE API

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