Is setting the BufferStrategy every time the game renders a good idea?

146 Views Asked by At

For some reason everyone sets their BufferStrategy to the BufferStrategy in their canvas whenever they render their game.

BufferStrategy bs;
Graphics2D g;

private void render() {
        bs = window.getCanvas().getBufferStrategy();

        if (bs == null) {
            window.getCanvas().createBufferStrategy(3);
            return;
        }

        g = (Graphics2D) bs.getDrawGraphics();

        bs.show();
        g.dispose();
}

// When thread starts
public void run() {
    while (running) {
       //Game loop stuff here.
       render();
      }
    }

Can you just set it once instead of every time the game re-renders?

0

There are 0 best solutions below