Skip to content

Commit fc5f8c9

Browse files
author
raytr
committed
Added sprite culling to improve performance
1 parent eccadb9 commit fc5f8c9

File tree

5 files changed

+8
-1
lines changed

5 files changed

+8
-1
lines changed
266 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
83 Bytes
Binary file not shown.

Diff for: src/game/client/GameCamera.java

+5
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@ public double getScreenHeight() {
4444
public double getScreenWidth() {
4545
return screenWidth;
4646
}
47+
48+
public boolean isVisible(double x, double y, double width, double height) {
49+
return (x + width > this.getX() && x < (this.getX() + this.getScreenWidth())
50+
&& y + height > this.getY() && y < (this.getY() + this.getScreenHeight()));
51+
}
4752
}

Diff for: src/game/client/Playfield.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public void draw(){
6666
if (canvasHeight != gameArea.getHeight()) gameArea.setHeight(canvasHeight);
6767
clear();
6868
for (Sprite s : spriteMap.values()){
69-
s.draw(gc);
69+
if (gameCamera.isVisible(s.getX(),s.getY(),s.getWidth(),s.getHeight())){
70+
s.draw(gc);
71+
}
7072
}
7173
createBorder();
7274
if (drawWinMsg){

0 commit comments

Comments
 (0)