I’m trying to create my first game in Java and I’ve seen most tutorials using a render method along the following lines:
public void render () {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.drawImage(image,0,0,getWidth(),getHeight(),null);
// render stuff
g.dispose();
bs.show();
}
I stumbled upon another guide recently using, in my eyes, a more understandable method:
public void paint (Graphics g) {
super.paint(g);
Graphics2d g2d = (Graphics2D) g;
// render stuff
// repaint() is then used to repaint the window
}
I’m leaning toward this being a case of performance. I too noticed the first paragraph of code, the one I currently use, is with JFrame and the latter one with JPanel. Which one would you recommend?
Thanks for the help!