-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackground.java
51 lines (46 loc) · 1006 Bytes
/
Background.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* e-LEMON-ators */
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
public class Background
{
private BufferedImage image;
private final int FRAME = 600;
private int xPos;
private int yPos;
public Background(int x, int y)
{
xPos = x;
yPos = y;
try {
image = ImageIO.read(new File("sprites/background.png"));
}
catch (Exception e) {
System.out.println("Error-Background");
}
}
public void draw(Graphics g)
{
g.drawImage(image, getX(), getY(), image.getWidth(), image.getHeight(), null);
xPos -= 1;
if (xPos <= -FRAME)
xPos = xPos + image.getWidth() * 2;
}
public void setX(int x)
{
xPos = x;
}
public void setY(int y)
{
yPos = y;
}
public int getX()
{
return xPos;
}
public int getY()
{
return yPos;
}
}