In my pursuit of a worms 2d-style view in my 2d game, I am using one large PNG or GIF image as the background
I made the following method to break this image into tiles so it can be accelerated
public void makeBack(String back)
{
BufferedImage background = getImage(back);
mapWidth = background.getWidth();
mapHeight = background.getHeight();
int numberXTiles = background.getWidth() / TILE_SIZE;
int numberYTiles = background.getHeight() / TILE_SIZE;
backMap = new BufferedImage[numberXTiles][numberYTiles];
for (int x = 0; x < numberXTiles; x++)
{
for (int y = 0; y < numberYTiles; y++)
{
backMap[x][y] = gc.createCompatibleImage(TILE_SIZE, TILE_SIZE,
Transparency.OPAQUE);
Graphics g = backMap[x][y].getGraphics();
g.drawImage(background.getSubimage(x * TILE_SIZE, y * TILE_SIZE,
TILE_SIZE, TILE_SIZE), 0, 0, null);
g.dispose();
if (backMap[x][y].getCapabilities(gc).isAccelerated())
{
System.out.println("True");
}
else
{
System.out.println("False");
}
}
}
background = null;
}
The problem is that it takes an insane amount of RAM on my system. The original image is of size 2048*2048 and is around 800KB as a GIF
when i run this method, the RAM usage in task manager rises to around 70,000KB which is huge.
when i try and make both the foreground and background, i get a java heap size out of memory error
i could increase the heap size but this is only a small game and that is more of a workaround than a real solution
i would appreciate some help/advice on why the size in RAM is so large and ways to alleviate this problem