在我的Java游戏中,我有一个玩家类,它有一个从精灵表中分配给它的BufferedImage。我刚刚添加了KeyAdapters和KeyListeners,只是在屏幕上移动播放器。但是,当我这样做时,它会留下图像的痕迹。
private void render() {
BufferStrategy bs = this.getBufferStrategy();
if(bs == null) {
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
p.render(g); //p is the player object
g.dispose();
bs.show();
}
public static void main(String[] args) {
Game game = new Game();
game.setPreferredSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
game.setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
game.setMaximumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
JFrame frame = new JFrame(game.TITLE);
frame.add(game);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
game.start();
}
答案 0 :(得分:0)