0

I've been using Monogame for a awhile now and I was just wondering what is the best way to load my content? Lets say i have an intervals system that constantly creates objects on the screen, so should I load the object's sprite in the game class and put the sprite variable in the constructor or should I put the content variable in the object constructor and load the sprite from within the object?

Btw by best way I mean I try to keep the framerate and use less memory, thx in advance!

stav12212
  • 1
  • 1
  • load object or texture only once and inside `LoadContent()` method. you can create your own loadcontent method if you don't wish to load all, but make sure it's executed only once. – Davor Mlinaric Feb 13 '15 at 12:12

2 Answers2

0

Best way for frame rate is to load it before game loop starts. But the best way for less memory is right when you need it and dispose of it after your done. Not necessarily mutually inclusive... pick your poison.

Steve H
  • 5,479
  • 4
  • 20
  • 26
0

You have 3 different solutions, and each will fit a different type of game.

Load everything in LoadContent

This will cause a longer initial startup time, but after everything is loaded, you wont have to wait for anything anymore. However keep in mind that this is only suited for small games such as Tetris, Arcanoid or Chess. Games that generally doesn't have a lot of content. Keep in mind that the more content you load, the more memory it will consume.

Load everything needed for the current scene

This is what most games does, since you wont load data for scenes that you never use, and you wont load data for scenes you're not yet accessing.

Load everything needed for the current scene (Extended)

Like the previous answer, but with a small twist. If possible, load content while displaying other content. For instance, as soon as the player finished the last step for completing a scene, initiate the loading of the next scene.

Arcanoid example: As soon as the ball hits the last block (or if you're brave, even as soon as you can calculate that the ball WILL hit the final block), initiate the loading of the content for the next scene. Let this load while the ball flies towards the final block, and also while displaying the score for the current scene (Time, deaths, bonuses, etc.)

And should the player actually close the dialogues before the scene has been loaded, show another loading scene while the data finishes loading. That way, there might only be 1-2 seconds of loading time instead of 10.

Remember to perform all this loading in a background thread.

Falgantil
  • 1,290
  • 12
  • 27