Skip to main content
gamedev.net
🔒 Locked

loading images in java

Started by prof_89 1 reply 550+ views
Original Post
prof_89
prof_89
Hi, im working on a game and for the moment my main class is flooded with "image-loading-code"... how can i load the images in a seperate class (imageload.class) ??
rasher_b2
rasher_b2
You would need to make a separate class like you've suggested. You could have a method such as getImage(imageName). It would be handy to store the images so they don't have to be loaded every time. You could use a hash map for this, using the image's path/name as a key. That way, when you request an image from the class it will look up the hash map and return the image. If the image hasn't been loaded then go ahead and load it.
harveypekar
harveypekar
javax.imageio.ImageIO.read(File file) works like a charm, just be sure to do it before you actually need the image.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.