我正在尝试用 Java 创建一个吃豆人游戏,到目前为止我已经显示了背景图像(蓝色和黑色的迷宫),但是我无法显示吃豆人的图像。当我尝试以与显示背景相同的方法显示他时,除非我稍微手动更改 Jframe 的大小,否则他不会出现。即便如此,当他出现时,他的图像右下角还有一个白色的小方块。我能做些什么来解决这个问题?有没有其他方法可以在其中插入 pacman 图像?
这是代码:
JFrame window = new JFrame();
ImageImplement pacman = new ImageImplement(new ImageIcon("C:\\Users\\16ayoubc\\Desktop\\Pacman-moving.gif").getImage());
ImageImplement panel = new ImageImplement(new ImageIcon("C:\\Users\\16ayoubc\\Desktop\\background.png").getImage());
pacman.setLocation(255, 255);
pacman.setVisible(true);
pacman.setOpaque(true);
window.add(pacman);
window.add(panel);
window.setVisible(true);
window.setSize(576,655);
window.setName("Pacman");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);