Java游戏图像缓冲留下尾巴

Java游戏图像缓冲留下尾巴,java,graphics,buffer,bufferstrategy,Java,Graphics,Buffer,Bufferstrategy,我有以下类(Snippet),在我的render()方法中,我使用BufferStrategy进行缓冲。我遇到的问题是,当我移动图像时,它会留下一条尾巴 我需要如何处理我的代码才能使它不显示尾部?代码如下: public class Main extends JFrame implements Runnable{ private BufferStrategy bufferStrategy; public synchronized void start(){

我有以下类(Snippet),在我的
render()
方法中,我使用
BufferStrategy
进行缓冲。我遇到的问题是,当我移动图像时,它会留下一条尾巴

我需要如何处理我的代码才能使它不显示尾部?代码如下:

public class Main extends JFrame implements Runnable{

    private BufferStrategy bufferStrategy;

    public synchronized void start(){
        Thread thread = new Thread(this);
        thread.start();
    }

    public void run(){
        // Main Game Loop
        this.render();
        // End Main Game Loop
    }

    protected void render(){
        if(bufferStrategy == null){
            this.createBufferStrategy(3);
            bufferStrategy = this.getBufferStrategy();
        }
        Graphics g = bufferStrategy.getDrawGraphics();
        // Loop through a list of items to draw
        for(GameObject go : gameObjects){
            Image sprite = go.getComponent(SpriteRenderer.class).getSprite();
            Vector2 pos = go.getComponent(Transform.class).getPosition();
            g.drawImage(sprite, (int)pos.x, (int)pos.y, this);
        }
        g.dispose();
        bufferStrategy.show();
        Toolkit.getDefaultToolkit().sync();
    }
}
编辑

我想出来了:

Graphics g = bufferStrategy.getDrawGraphics();
super.paint(g);

在再次绘制控制盘的位置之前,您需要在每次控制盘移动时刷新并将画布重新绘制为黑色