Combining Images

Hello everyone. I’m working on a tile-based game, but it is running extremely slowly. I’m hoping you all can help me out with speeding it up.

Right now, the background is made up of dozens of invididual tile images that are read from a file. I create a BufferedImage called background and then draw all the tiles onto the BufferedImage using g.drawImage. Since the background never changes after it is first created, I then just draw the background onto the screen whenever it updates.

However, I found the program ran faster if I drew the individual tiles to the screen for each update rather than the background BufferedImage. I’m assuming I did something wrong, because it doesn’t make sense that a lot of small images would be drawn faster than one big image.

Is there a problem with the way I created the background BufferedImage? I appreciate any help anyone can give.

I don’t know how you’re creating your images, but images greater than 256x256 aren’t going to be accelerated anyway. So it being slower is to be expected.

Actually drawing several small images is faster. The memory consumption per image is widthheightdepth. A 640x480 image at 16-bit depth takes up 600 KB of space. Add in the amount of space for your tiles and a huge chunk of ram is being taken up. Also, the BufferedImage probably is not being accelerated (It’s being created in System Ram). My advice is either draw onto a VolatileImage which so long as you have a mediocre graphics card will be accelerated or get rid of the background image all together.

Thanks for the help. I kept the tiles as BufferedImages and drew them onto a VolatileImage, which I then display. This made things a lot faster.

But now I’m running into another problem. I want to display semi-transparent images on top of the background image, so it would give one of the tiles a reddish or bluish tint, but it displays the semi-transparent BufferedImage as opaque. This didn’t happen when the background was BufferedImage. Is it possible to display a semi-transparent BufferedImage on a VolatileImage?

It should be possible to draw semi-transparent tiles onto a VolatileImage. However, the VolatileImage you are drawing onto can not be transparent unless you want to lose hardware accleration (Support for hardware acceleration of translucent and transparent VolatileImages is not completed yet.) Hopefully with Mustang, Sun will have complete support for hardware accleration of images.