I was wondering if it would be more efficient to render a single BufferedImage instead of rendering a bunch of BufferedImages in a double for loop?
I have an idea of how to do it, I just don't know what methods in BufferedImage you would use to create the bigger image. I'm assuming it has to do with setRGB()
but what would the pseudo code look like when using getRGB
on all the smaller images?
The reason I was thinking it would be more efficient to render that way is because you can render only a smaller portion of it (using getSubImage()
) and only edit the image when it needs to.
Here's my Rendering code right now.
public void render(Graphics g, int x, int y, int width, int height)
{
int renderX = 0;
int renderY = 0;
for (int i = x; i < width; i++)
{
for (int j = y; j < height; j++)
{
if(layerData[i][j] != null)
g.drawImage(layerData[i][j].getImage(), renderX * Tile.SIZE, renderY * Tile.SIZE, null);
renderY++;
}
renderY = 0;
renderX++;
}
}
layerData
is the Maps Tile Data and getImage()
returns that Tile's BufferedImage.
PS: I am using a TileSheet.