For my game I want to make a map of the world. Per country I made a file with the border of the country and the rest of background is transparent. This way all my files have the same width and height. My problem is that XNA only renders the first image and it does it in an alphabetical order. For example: if I change the name of the first sprite so it isn't first in alphabetical order, it just renders the first sprite.
The sprites are loaded in a sortedlist and each key is the name of the continent + the name of the country. And I loop through this list to render each sprite.
Code to load the files:
protected override void LoadContent()
{
DirectoryInfo objDirectory = new DirectoryInfo(Game.Content.RootDirectory + "/Regions");
FileInfo[] objFiles = objDirectory.GetFiles("*.*");
objSpritebatch = new SpriteBatch(Game.GraphicsDevice);
foreach (FileInfo File in objFiles)
{
string[] FileName = File.Name.Split("_".ToCharArray());
string strContinent = FileName[1] + "/" + FileName[2].Substring(0, FileName[2].Length - 4);
lstBorders.Add(strContinent, Game.Content.Load<Texture2D>("Regions\\" + Path.GetFileNameWithoutExtension(objFiles[0].Name)));
}
base.LoadContent();
}
Code to render the files:
public override void Draw(GameTime gameTime)
{
objSpritebatch.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend);
foreach(KeyValuePair<string, Texture2D> Border in lstBorders)
{
objSpritebatch.Draw(Border.Value, new Rectangle(0, 0, 800, 400), Color.White);
}
objSpritebatch.End();
base.Draw(gameTime);
}
I allready did some research and hoped it would be fixed by using those parameters in the begin command but it didn't help. I hope I gave you all the code you need.