Reputation: 1208
Hey guys can anybody tell me why my background is not drawing
background = new ImageIcon("C:\\Users\\Aiden Strydom\\Desktop\\Java Game\\Images\\background.jpg").getImage();
}
@Override
public synchronized void DrawScreen(Graphics2D g)
{
int Width = screen.getWidth();
int Height = screen.getHeight();
ImageLocation.x %= Width; //Make image wrap around
ImageLocation.y %= Height;
if(ImageLocation.x < 0)
ImageLocation.x += Width;
if(ImageLocation.y < 0)
ImageLocation.y += Height;
int x = ImageLocation.x;
int y = ImageLocation.y;
g.drawImage(background, x, y, null);
g.drawImage(background, x - Width, y, null);
g.drawImage(background, x, y - Height, null);
g.drawImage(background, x - Width, y - Height, null);
}
I just see the default grey screen, and the debugger does hit the g.drawImage method!
Update: Actually nothing wrong with the code - some how the background picture got deleted out of the folder - when i created a new background picture it Worked.
Upvotes: 0
Views: 597
Reputation: 44240
Override the paintComponent
method of the component you want to custom paint. Draw on its Graphics
object.
Upvotes: 1