Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

doogle

[java] Preloading images

This topic is 5893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a game, and it has a 800x500 gif as a background picture. In the first few seconds of the game, you have to sit there and watch it and other gifs load. Instead I wanted to preload the images, but I could find any convincing solutions on how to do this. Any suggestions? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Check this method out, it uses MediaTracker to wait until the picture is loaded. Then it returns the image if no error occured.

Furtermore, to use it:

Image myImage = getImage("gfx/blabla.jpg");

It adds the DocumentBase in the method.


private Image getImage(String imageName) {
MediaTracker mt = new MediaTracker(this);
Image image = getImage(getDocumentBase(),imageName);
mt.addImage(image,0);
try {
mt.waitForAll();
} catch(InterruptedException ex) {}
if(mt.isErrorAny()) {
System.out.println("error while loading: "+imageName+" ("+getDocumentBase()+imageName+")");
return null;
}
return image;
}


[edited by - Scorpion on June 3, 2002 7:47:17 AM]

Share this post


Link to post
Share on other sites
Hey people, it would be good if you checked first previous threads posted here, the question about how to preload images has been asked about 3 or 4 times since I´m here..., you have to set the forum to display the messages posted in the last 30 or 45 days...

You can find different solutions there....

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!