2
\$\begingroup\$

I'm writing a game using LWJGL and Java, and was wondering if there were best practices for when to load resources.

I have seen examples that load all resources when initializing the game (XNA), ones that load the new resources needed for each level while referencing the already loaded assets again.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

It depends on how many resources you have and how they perform with your game. I recommend to start with a simple solution, which means loading all the assets at the beginning, so you can use them anytime. Once the game performs slowly because of the memory problems consider writing some kind of manager, which will load assets in a smarter way.

What I recommend is to ready all your assets through a "dummy" manager, which will at the beginning just load all the resources and provide them. But your code will treat it as a black box providing assets. If you need to make changes, then you just change the manager and not game code. Once the game gets slower, you can add simple tricks to your manager. For example, it can watch what assets are requested per level and pre-load them for this level and drop those that are not used, which would be the first optimization I would do in your case.

\$\endgroup\$

You must log in to answer this question.

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