Added parallax, started documentation
parent
bcd896ed45
commit
ca97774204
|
@ -0,0 +1,25 @@
|
||||||
|
# Function Overview
|
||||||
|
|
||||||
|
This document intended to assist developers who seek to extend the game by modifying source code in src/.
|
||||||
|
|
||||||
|
## Classes
|
||||||
|
|
||||||
|
### BackgroundImage
|
||||||
|
|
||||||
|
Its constructor takes the following arguments:
|
||||||
|
|
||||||
|
`int x, int y, BufferedImage backgroundImage, int width, int height, int parallaxRatio`
|
||||||
|
|
||||||
|
Draws a background image that moves one pixel every `parallaxRatio` pixels when `BackgroundImage.draw()` is called.
|
||||||
|
|
||||||
|
### Camera
|
||||||
|
|
||||||
|
placeholder
|
||||||
|
|
||||||
|
## Utility Functions
|
||||||
|
|
||||||
|
These functions are located in the `public final` class UtilityFunction; please note that the UtilityFunction constructor is private to prevent initialization.
|
||||||
|
|
||||||
|
### readFromFile
|
||||||
|
|
||||||
|
placeholder
|
|
@ -4,22 +4,21 @@ import java.awt.image.BufferedImage;
|
||||||
public class BackgroundImage {
|
public class BackgroundImage {
|
||||||
public int x, y;
|
public int x, y;
|
||||||
public int width, height;
|
public int width, height;
|
||||||
|
public int parallaxRatio;
|
||||||
public BufferedImage backgroundImage;
|
public BufferedImage backgroundImage;
|
||||||
|
|
||||||
public BackgroundImage(int x, int y, BufferedImage backgroundImage, int width, int height) throws SpriteException {
|
public BackgroundImage(int x, int y, BufferedImage backgroundImage, int width, int height, int parallaxRatio) {
|
||||||
int compressionRatio;
|
|
||||||
|
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
this.backgroundImage = backgroundImage;
|
this.backgroundImage = backgroundImage;
|
||||||
// compressionRatio = Math.max(backgroundImage.getWidth() / width, backgroundImage.getHeight() / height);
|
this.parallaxRatio = parallaxRatio;
|
||||||
// this.backgroundImage = backgroundImage.getSubimage((backgroundImage.getWidth() - width)/2,
|
|
||||||
// (backgroundImage.getHeight() - height)/2, width, height);
|
|
||||||
}
|
}
|
||||||
public void draw(Graphics g){
|
public void draw(Graphics g){
|
||||||
g.drawImage(backgroundImage, x, y, width, height, null);
|
g.drawImage(backgroundImage, x-GamePanel.camera.x/parallaxRatio % width, y, width, height, null);
|
||||||
|
// added to prevent the background image from disappearing
|
||||||
|
g.drawImage(backgroundImage, x-GamePanel.camera.x/parallaxRatio % width + width - 1, y, width, height, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue