GTGE API

com.golden.gamedev.object.background
Class ParallaxBackground

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

public class ParallaxBackground
extends Background

ParallaxBackground class is a background composed by several backgrounds.

This class automatically handles displaying and scrolling of the stacked backgrounds. The backgrounds are normalized to the size and position of the largest background in the stack. This way, the largest coordinate system is presented, and all backgrounds move together at a smooth rate.

The backgrounds is rendered from the first background on the stack to the last background on the stack, in other word the first background on the stack will be at the back of other backgrounds.

Parallax background usage example :

    ParallaxBackground background;
    Background bg1, bg2, bg3;

    background = new ParallaxBackground(new Background[] { bg1, bg2, bg3 });
    // bg1 is at the back of bg2 and bg2 is at the back of bg3
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.golden.gamedev.object.Background
screen, x, y
 
Constructor Summary
ParallaxBackground(Background[] stack)
          Creates new ParallaxBackground.
 
Method Summary
 Background[] getParallaxBackground()
          Returns the stacked parallax backgrounds.
 void render(Graphics2D g)
          Renders background to specified graphics context.
 void setLocation(double xb, double yb)
          Sets background location to specified coordinate.
 void setParallaxBackground(Background[] stack)
          Sets parallax background stacked backgrounds.
 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 com.golden.gamedev.object.Background
getClip, getDefaultBackground, getHeight, getWidth, getX, getY, move, render, setClip, setClip, setSize, setToCenter, setToCenter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParallaxBackground

public ParallaxBackground(Background[] stack)
Creates new ParallaxBackground.

Method Detail

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

update

public void update(long elapsedTime)
Description copied from class: Background
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.

Overrides:
update in class Background

render

public void render(Graphics2D g)
Description copied from class: Background
Renders background to specified graphics context.

Overrides:
render in class Background
Parameters:
g - graphics context

getParallaxBackground

public Background[] getParallaxBackground()
Returns the stacked parallax backgrounds.


setParallaxBackground

public void setParallaxBackground(Background[] stack)
Sets parallax background stacked backgrounds.


GTGE API

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