How to preload graphics?

Hey!

I have a problem that i dont really know how i can get around, and at the moment i have a quite clumpsy way to solve it.

The thing i want to accomplish is to be sure that all the graphics that the screen is about to render really is “loaded”, as it is now, sometimes all the gfx aint showing when i start the game, this is really painfull to see, and really not something that i want to have in the finished game.

So…
Is there a way to make a loading screen that can feel when all the gfx is loaded into memory, so that I can be sure that the screen will render all elements when i enter it?
Now i make the system sleep 1-3 secs, this works most of the time, but sometimes its just annoying, a neater way would be that the game knows when all the gfx is loaded and dont wait a sec longer that nececery.

As you might be able to see, im pretty new to game programing in general, so all your tips and trix will be most helpfull!

Thanx

With toolkit… use a MediaTracker.

Or just use ImageIO like the rest of us :wink:

hehe you got a point there, at this moment im using toolkit for image loading and so on, i should check into ImageIO more, does anyone know any nice tutorials for using ImageIO with awt?

BufferedImage img=ImageIO.read(new BufferedInputStream(getClass().getResourceAsStream("/gfx/foo.png")));

import javax.imageio.*; and try/catch IOException

If you want em managed in 1.4.x you need to copy em over once with alpha composite set to AlphaComposite.Src (the same is true with that toolkit stuff).

Wow!

Seams to work neater than toolkit hehe, im doing a complete makeover in the graphic system in the game so this is perfect for me, making the whole system a bit more stable and appropriate for gameing =)

Tnx for the help!

In simpler games I just use the MediaTracker and ImageIcons.


ImageIcon pic = new ImageIcon("folder/fileLocation.gif");
if (pic.getImageLoadStatus() == MediaTracker.COMPLETE)
     g.drawImage(pic.getImage(),x,y,width,height,pic.getImageObserver());

It’s pretty simple! ;D