0
votes

I am making a test xna game as a learning exercise and I have a small question about using 2d textures. Basically the game is a grid of different 'tiles' which are taken from a text map file. I basically just parse through the file when initializing a level and create a matrix of the different tile types. The level is essentially a tub of wall tiles and spikes. So essentially, there are lots of wall tiles and multiple spike tiles and then lots of empty tiles. However, there are four types of wall tile and spike textures to cover different directions.

My question is what is the best way to load the textures for each of the tile? Do I load individual textures for each tile? i.e when I create a tile, pass it a texture2d which I can draw and load the texture at the same time. This seems like a good way, but then I have to load each tiles texture individually and this seems wasteful.

The other option I can think of is to use a static texture in the tile struct an then simple load this texture as a tile atlas with the different walls and spikes. This way I am only loading a single texture, and then when drawing I just move a rectangle to the area of the appropriate tile within the sprite.

I am not sure which of these ways would be optimal from a performance perspective, or if there is an alternative approach?

Thanks in advanmce

1
Define "best"? Do you want to save memory, improve your frame rate, reduce development time or something else entirely? Also, I noticed you posted the exact same question here, should I post the exact same answer on both? gamedev.stackexchange.com/questions/59109/…craftworkgames

1 Answers

4
votes

The wonderful thing about the content pipeline is that when you do

Content.Load<Texture2D>("sometexture");

It doesn't load the Texture2D everytime. The content pipeline is smart enough to load it once and send back the same Texture2D for that texture everytime. It would actually be worse if you made the static struct.