Another way to do it, is to do a translation at the beging :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Graphics2D g2D = (Graphics2D)this.backBuffer.getGraphics();
... AffineTransform trans = g2D.getTransform();
g2D.translate(-camera.x*40,-camera.y*40);
for(int y=camera.y;y<camera.y+12;y++) { for(int x=camera.x;x<camera.x+20;x++) { ... } }
g2D.setTransform(trans); |
By the way, the "Position position = new Position(x,y);" is "horrible"

. You are creating 240 objects by frame for nothing. Create a method "Position.set(x,y);" and reuse the object.