I am going through the cherno project videos, but I don't understand why the code does what it does.
render gets called ecer time we loop through, I have omitted the rest of the code as it is all basic game loop/threads. However this bit i don't understand. Can you please explain the details of how it works, so i feel like I am not just copying.
//these definitions confuse me a bit
private BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
//I know why this gets called
public void render()
{
//this I don't understand
BufferStrategy bs = getBufferStrategy();
if (bs == null)
{
createBufferStrategy(3);
return;
}
//Screen is our own class, this just fills and array with colour at the moment
Screen.render();
//this just transferes the arrays accross
for (int i = 0; i < pixels.length;i++)
{
pixels[i] = Screen.pixels[i];
}
//I didn't know you could define objects like this, can someone please explain this
Graphics g = bs.getDrawGraphics();
//these methods are fine
g.setColor(Color.BLACK);
g.fillRect(0, 0, getWidth(), getHeight());
g.drawImage(image, 0, 0, getWidth(), getHeight(),null);
//I am assuming this puts the rendered image to the buffer
g.dispose();
//and that this renders to the screen
bs.show();
}
thank you