2Dgraphics and sound

Hi

I’m writing an application game, and i’m at the part where im adding graphics and sound. So now, what would be the simplest & fastest? I’m thinking of using AudioClip for sound (from Applet) but think I read somewhere that that has a memory leak. Also, should it be used in a application? I’ve gotten it to work in a simple application but I haven’t tested it in a game situation to check for slowdown.

And what is the easiest/best way to load images? currently, I’m using Toolkit.getToolkit().getImage().

Thanks…

java.imageio.ImageIO.read() is nice and easy. But as far as I know it doesn’t return a managed image, so for best performance you should re-draw it to a BufferedImage created with Component.createImage() / GraphicsConfiguration.createCompatibleImage() etc.
Someone correct if i’m wrong…

You are correct for 1.4.
With Java 1.5 and up ImageIO is the best way to go as it will return managed images.
(For 1.4 you can always copy the image to a managed image before you use it.)

What is the difference between a normal image and a managed image? I read in a tuturial you’re supposed to use GraphicsConfiguration.createCompatibleImage() but it didn’t explain why.

Thanks for the help so far.

A managed image will be copied to VRAM so it gets accelerated without you having to do anything. It is a ‘normal’ image that is accelerated behind the scenes like a typical volatile image would be.

Compatible images are good because they are created in a format that doesn’t require conversion to be blitted to the screen.

Some things will invalidate the JRE’s ability to accelerate the image for you… basically if you get a reference to the raster so that you might modify the image then it isn’t possible for the image to be accelerated automatically.

I’m thinking of using AudioClip for sound (from Applet)

If there isn’t a good reason… don’t :>

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=Sound;action=display;num=1062877058;start=1#1

The code shows a very basic way for managing/playback of samples. Well, it works and it’s all you need at the beginning.

With AudioClip you have a (rather huge) delay each time a sample is played for the first time.

That piece of code there has only a delay once the very fist time one of the samples is played (because the creation of the default mixer takes some msecs). It’s somewhat ignoreable. However you could fix that by creating a mixer by yourself.