I'm making a 2D game and drawing to a surface inside a Frame. The problem is this, I am looping through the background and drawing the background image (using a image tiled), here is the result:
Note: I set the frame to 640,480
As you can see the top and left sides are off by a few pixels, I'm mainly worried about the top..
I am using this code to initialize the frame:
frame = new Frame(_title);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.addMouseListener(new Mouse());
frame.addKeyListener(new Keyboard());
frame.setSize(new Dimension(width, height));
frame.setResizable(false);
frame.setBackground(Color.lightGray);
frame.setVisible(true);
frame.createBufferStrategy(2);
And here is how I am drawing the background:
for(int x = 0; x < GameClient.width; x+= 32) {
for(int y= 0; y< GameClient.height; y+= 32) {
g.drawImage(floor, x , y, null);
}
}
I would have thought that it would work fine, but obviously not..
What am I doing wrong, or how can I fix this?
Thanks.