I am developing a game (in Java) that is going to have a lot of textures and images in it.

What is the most efficient way to load all the textures? I was thinking on pre-loading all the images instead of loading them during runtime (because during runtime they will be loaded over and over again).

I'll be happy to hear your opinion on those strategies, and also, if you have a better strategy I would like to hear that.


1 Answer 1


The question you have to ask yourself is, how often will the textures be used? Based on the answer you have a few options:

  • If multiple textures are expected to be visible on the screen at the same time, they all have to be pre-loaded, and remain in memory until they are drawn.
  • If multiple textures are part of different areas of your game (like on different levels) then you can pre-load all textures on the current level, and once the user moves to the next level, unload previous assets and load the ones on the new level.
  • In the case of an open-world game, where the line between the two choices above are slightly blurred, divine the map into "chunks", and when moving to a new chunk, un-load all assets on the previous one, and load the ones on the new chunk.

For most machines out there, the best you can do is pre-load as much as possible. If you are worried that a machine might run out of memory, maybe you'd have to ask yourself if using less textures, or smaller textures is preferred.

  • \$\begingroup\$ Thanks for the answer. I have tried pre loading the textures based on the levels and it working slightly faster but every time I change ga state it takes some time to load all the images and then it changes the textures so I thought maybe adding a statement that will appear during the loading. Do you know how to do so? \$\endgroup\$ Commented Apr 15, 2020 at 10:50
  • \$\begingroup\$ @TairGalili Loading always takes time, that's why loading screens are a thing, that's normal. Do you mean how to add a loading screen between levels? \$\endgroup\$ Commented Apr 15, 2020 at 10:53
  • \$\begingroup\$ Yes, I know that loading takes time and it now actually makes sense to me now (when I pre loaded the textures there was no loading at all and I didn't understand why loading screens are necessary) \$\endgroup\$ Commented Apr 15, 2020 at 11:22
  • \$\begingroup\$ @TairGalili I'm not sure how its best done in Java. But the usual design is, you have your main thread display a loading screen (it can be as simple as displaying the text Loading on the screen), then have another thread that is loading all the needed assets in the background. \$\endgroup\$ Commented Apr 15, 2020 at 12:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .