I really need help with this, I'm building a 2d sandbox game and when you select a world size, it begins to load the textures and stuff needed to play, but depending on the world size, this can be long or short. For instance, if you choose Huge it takes 5+ min, the reason, I have a grid setup as an array, the bigger the world, the bigger the array, when every GridSpace initializes, it loads 2 textures, it's alpha and rgb, in reality, it's only 8 images, but these 8 images are being loaded hundreds to thousands of times, how can I setup it so It loads only once? (I'm using Slick-Utils and when it's a static Texture the Texture Load doesn't work, on can only be on non-static textures, and Getters and setters don't help)
Members - Reputation: 3445
Posted 06 July 2014 - 07:44 PM
Have your texture loader cache your textures in a HashMap keyed on the file name. When you ask it to load a texture, it first checks the cache to see if the texture exists. If it does, it returns the existing instance rather than loading it from disk again.