|
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
public class Background
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).
com.golden.gamedev.object.background
,
Serialized FormField 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 |
---|
public static Dimension screen
setClip(int, int, int, int)
protected double x
x
coordinate.
setLocation(double, double)
protected double y
y
coordinate.
setLocation(double, double)
Constructor Detail |
---|
public Background(int w, int h)
Clipping area is the viewport of the background, anything outside viewport area will not be rendered.
w
- background widthh
- background heightpublic Background()
Clipping area is the view port of the background, anything outside clipping area will not be rendered.
Method Detail |
---|
public static Background getDefaultBackground()
public double getX()
x
coordinate of this background.
public double getY()
y
coordinate of this background.
public int getWidth()
public int getHeight()
public void setSize(int w, int h)
public void setLocation(double xb, double yb)
xb
- the x
coordinate of the backgroundyb
- the y
coordinate of the backgroundpublic void move(double dx, double dy)
public void setToCenter(int x, int y, int w, int h)
public void setToCenter(Sprite centered)
public void setClip(int x, int y, int width, int height)
By default background viewport is as large as screen size.
screen
public void setClip(Rectangle r)
By default background viewport is as large as screen size.
screen
public Rectangle getClip()
public void update(long elapsedTime)
The implementation of this method provided by the Background
class does nothing.
public void render(Graphics2D g)
g
- graphics contextpublic void render(Graphics2D g, int xbg, int ybg, int x, int y, int w, int h)
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.
g
- graphics contextxbg
- background x-coordinateybg
- background y-coordinatex
- screen start x clippingy
- screen start y clippingw
- clipping widthh
- clipping height
|
GTGE API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |