嘿家伙可以告诉我为什么我的背景不是画画
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);
}
我只看到默认的灰色屏幕,调试器确实点击了g.drawImage方法!
更新:实际上代码没有任何问题 - 有些背景图片是如何从文件夹中删除的 - 当我创建一个新的背景图片时它已经工作了。
答案 0 :(得分:1)
覆盖要自定义绘制的组件的paintComponent
方法。在其Graphics
对象上绘制。