What is the fastest way to load Textures in XNA

137 views Asked by At

I'm a student using the latest version of Microsoft XNA for learning purposes.

I need to load a whole lot of texture from the Content folder (or more specifically a folder called Tiles inside the Content folder) and I really don't want to type the following code 100 times:

texture = Content.Load<Texture2D>("texture");

I realize I could change the names of the files and run through a loop to load them, but this seems inefficient for finding specific tiles if there's a way I could keep the names. I am just looking for a way to load all of these that saves development time.

Also, the files are in .BMP form, if that matters.

1

There are 1 answers

0
Steven On

Keep in mind that every texture needs to be loaded at least once. So using

texture = Content.Load<Texture2D>("texture");

is fine to repeat for different textures, as long as you don't repeat it for the same texture.

I've learned is to load all textures in the LoadContent() of game1.cs, that method is only called once at the moment the game starts. So they're all ready to be used for the rest of the game.

There's also a Lazy Loading practice, where the texture is only loaded for when the object appears. But you should be aware that the texture loading won't repeat itself for each object.