【问题标题】:Java Game Image Buffering Leaves TailJava 游戏图像缓冲留下尾巴
【发布时间】:2014-08-05 21:44:52
【问题描述】:

我有以下类(片段),在我的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);

【问题讨论】:

    标签: java graphics buffer bufferstrategy


    【解决方案1】:

    您需要在每次轮子移动时刷新并将 Canvas 重新绘制为黑色,然后再重新绘制轮子的位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-05
      • 1970-01-01
      • 2019-06-14
      • 2014-04-09
      • 2019-03-12
      • 2013-04-14
      • 1970-01-01
      相关资源
      最近更新 更多