When to load textures?

I am currently working on several projects of phones on the phone (although the question may also be relevant for iphone / android), and this made me wonder when the best time to download textures from the content manager.

At first I downloaded them all from the Game base class and passed them as needed. Having quickly become ill with this, I created a small class of resource manager, which I pass on to everyone that requires it.

So, I think that perhaps the best thing is that I really load the texture when the class requires it and then assigns it to a variable, so when I need it, it will be ready ... is this the best way (efficient ?, fast ?) to handle downloadable resources? If not, what would you recommend, will I go about this?

+3
source share
1 answer

Do not create a resource class class. Just pass the XNA class ContentManager(the instance you get from Game.Content).

The default content manager will automatically handle the reuse of downloaded objects for you. This way, you can Content.Load<Texture2D>("something")from several places, and you will always return the same instance of the texture.

, , Update Draw, Game, : LoadContent , ContentManager.

LoadContent.

- (, ), LoadContent Update method ( , , ).

. , , . , ContentManager ( ), (Game Content, ). , .

+7

Source: https://habr.com/ru/post/1768549/