I am making a game and I want to add the option to fullscreen so it scales all graphics to the new expanded JFrame. Code works great and does exactly what I want, but now I have a problem and I'm assuming it's a memory problem or something because what I am doing is drawing everything to a buffered image and then drawing the buffered image scaled to the JFrame's size. Before, when I just drew everything directly to the frame, I would get ~900 frames constant. But when I implement my new method it drops right away to 120 frames and freezes for about half a second every few seconds.
This is the current method:
private void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
this.createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
BufferedImage screen = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = (Graphics2D) screen.getGraphics();
g2d.translate(-Camera.getX(), -Camera.getY());
level.render(g2d);
handler.render(g2d);
g2d.translate(Camera.getX(), Camera.getY());
g.drawImage(screen, 0, 0, fullWidth, fullHeight, null);
bs.show();
g2d.dispose();
g.dispose();
}
And this is what the method looked like before that was giving 900 or more frames with no freezing:
private void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
this.createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
Graphics2D g2d = (Graphics2D) g;
g2d.translate(-Camera.getX(), -Camera.getY());
level.render(g);
handler.render(g);
g2d.translate(Camera.getX(), Camera.getY());
bs.show();
g.dispose();
}