-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameCamera.java
More file actions
57 lines (44 loc) · 1.32 KB
/
GameCamera.java
File metadata and controls
57 lines (44 loc) · 1.32 KB
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
52
53
54
55
56
57
package mainPackage;
public class GameCamera {
private Handler handler;
private float xOffset, yOffset;
public GameCamera (Handler handler, float xOffset, float yOffset) {
this.handler = handler;
this.xOffset = xOffset;
this.yOffset = yOffset;
}
public void checkBlankSpace() {
if(xOffset < 0) {
xOffset = 0;
} else if(xOffset > handler.getWorld().getWidth() * Tile.TILEWIDTH - handler.getWidth()) {
xOffset = handler.getWorld().getWidth() * Tile.TILEWIDTH - handler.getWidth();
}
if(yOffset < 0) {
yOffset = 0;
} else if(yOffset > handler.getWorld().getHeight() * Tile.TILEHEIGHT - handler.getHeight()) {
yOffset = handler.getWorld().getHeight() * Tile.TILEHEIGHT - handler.getHeight();
}
}
public void centerOnEntity(Entity e) {
xOffset = e.getX() - handler.getWidth() / 2 + e.getWidth() / 2;
yOffset = e.getY() - handler.getHeight() / 2 + e.getHeight() / 2;
checkBlankSpace();
}
public void move(float xAmt, float yAmt) {
xOffset += xAmt;
yOffset += yAmt;
checkBlankSpace();
}
public float getxOffset() {
return xOffset;
}
public void setxOffset(float xOffset) {
this.xOffset = xOffset;
}
public float getyOffset() {
return yOffset;
}
public void setyOffset(float yOffset) {
this.yOffset = yOffset;
}
}