/// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.

            spriteBatch = new SpriteBatch(GraphicsDevice);
             Dictionary<int, string> Textures;
             Map = TileMap.ReadInMap(Content.RootDirectory + "/Map1.map", out Textures);
             string[] Strings = new string[Textures.Values.Count];
             Textures.Values.CopyTo(Strings, 0);
             foreach (TileLayer layer in Map.Layers)
             {
                 layer.AddTextures(Content, Strings);
             }

            nakedplayer = Content.Load<Texture2D>("Sprites/8_way_large");
            SpriteAnimation animation = new SpriteAnimation(nakedplayer);
            FrameAnimation Down = new FrameAnimation(10, nakedplayer.Width / 4, nakedplayer.Height / 2, 1, (nakedplayer.Width / 4)*0, 0, new Point(0, 0));
            FrameAnimation DownLeft = new FrameAnimation(10, nakedplayer.Width / 4, nakedplayer.Height / 2, 1, (nakedplayer.Width / 4) * 1, 0, new Point(0, 0));
            FrameAnimation Left = new FrameAnimation(10, nakedplayer.Width / 4, nakedplayer.Height / 2, 1, (nakedplayer.Width / 4) * 2, 0, new Point(0, 0));
            FrameAnimation UpLeft = new FrameAnimation(10, nakedplayer.Width / 4, nakedplayer.Height / 2, 1, (nakedplayer.Width / 4) * 3, 0, new Point(0, 0));
            FrameAnimation Up = new FrameAnimation(10, nakedplayer.Width / 4, nakedplayer.Height / 2, 1, (nakedplayer.Width / 4) * 0, (nakedplayer.Height / 2), new Point(0, 0));
            FrameAnimation UpRight = new FrameAnimation(10, nakedplayer.Width / 4, nakedplayer.Height / 2, 1, (nakedplayer.Width / 4 )* 1, (nakedplayer.Height / 2), new Point(0, 0));
            FrameAnimation Right = new FrameAnimation(10, nakedplayer.Width / 4, nakedplayer.Height / 2, 1, (nakedplayer.Width / 4) * 2, (nakedplayer.Height / 2), new Point(0, 0));
            FrameAnimation DownRight = new FrameAnimation(10, nakedplayer.Width / 4, nakedplayer.Height / 2, 1, (nakedplayer.Width / 4) * 3, (nakedplayer.Height / 2), new Point(0, 0));

            animation.AddAnimations("Down", Down);
            animation.AddAnimations("DownRight", DownLeft);
            animation.AddAnimations("Right", Left);
            animation.AddAnimations("UpRight", UpLeft);
            animation.AddAnimations("Up", Up);
            animation.AddAnimations("UpLeft", UpRight);
            animation.AddAnimations("Left", Right);
            animation.AddAnimations("DownLeft", DownRight);

            player = new Player(animation, new Vector2(200,200), 30f, 0);

            // TODO: use this.Content to load your game content here
        }
        private void loadMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            openFileDialog2.InitialDirectory = WorkspacePath;
            openFileDialog2.Filter = "Map File|*.map|Xml File|*.xml|All Supported Files|*.map;*.xml";

            Dictionary<int, string> texturesToLoad = new Dictionary<int, string>();
            Dictionary<string,Texture2D> masterTexturesToLoad = new Dictionary<string,Texture2D>();

            if (openFileDialog2.ShowDialog() == DialogResult.OK)
            {
                Map = TileMap.ReadInMap(openFileDialog2.FileName, out texturesToLoad);
            string extensFound = "";

            try
            {
                foreach (KeyValuePair<int, string> texturespaths in texturesToLoad)
                {
                    foreach (string ext in Extensions)
                    {
                        if (File.Exists(texPathAddress.Text + "\\" + texturespaths.Value + ext))
                        {
                            extensFound = ext;
                            break;
                        }
                    }

                    FileStream stream = new FileStream(texPathAddress.Text + "\\" + texturespaths.Value + extensFound, FileMode.Open);

                    Texture2D texture = Texture2D.FromStream(GraphicsDevices, stream);

                    stream.Close();
                    stream.Dispose();
                    if (!masterTexturesToLoad.ContainsKey(texturespaths.Value))
                    {
                        masterTexturesToLoad.Add(texturespaths.Value,texture);
                        //masterPathToLoad.Add(texturespaths.Value);

                    }

                }

            }
            catch (FileNotFoundException ex)
            {
                MessageBox.Show("Cannot Load Layer File. the texure: " +
                    ex.FileName +
                    " Could not be found in the content folder you have chosen. Content Folder Selector button has been enabled, you have can choose another Directory that has the resource you are trying to load.", "RESOURCE FILE NOT FOUND");
                btnAddFiles.Enabled = true;
            }

                foreach (TileLayer layer in Map.Layers)
                {
                    dictLayer.Add(layer.LayerName, layer);
                    LayerList.Items.Add(layer.LayerName);

                    foreach (KeyValuePair<string,Texture2D> tex in masterTexturesToLoad)
                    {
                    layer.AddTexture(tex.Value);
                    }

                    if (Map.Layers.IndexOf(layer) == Map.Layers.Count - 1)
                    {
                        foreach (KeyValuePair<string, Texture2D> tex in masterTexturesToLoad)
                        {
                            TextureList.Items.Add(tex.Key);
                            dictTextures.Add(tex.Key, tex.Value);
                            Image img = Image.FromFile(texPathAddress.Text + "\\" + tex.Key + extensFound);
                            dictImages.Add(tex.Key, img);
                        }

                        currentLayer = layer;
                        LayerList.SelectedIndex = LayerList.Items.Count - 1;
                        activateControls();

                    }

                }

            }
        }
        public static TileMap ReadInMap(string fileName,
        out Dictionary<int, string> textureNames
         )
        {

            textureNames = new Dictionary<int, string>();

            XmlDocument DocToLoad=new XmlDocument();
            DocToLoad.Load(fileName);
            TileMap tempMap= new TileMap();
            XmlNode node = DocToLoad.DocumentElement;

            foreach (XmlNode tempnode in node.ChildNodes) {
                if (tempnode.Name == "TileLayer")
                {
                  
                  TileLayer tempLayer =  TileLayer.ReadInLayer(tempnode, out textureNames);
                  tempMap.Addlayer(tempLayer);
                 }
                else if (tempnode.Name == "CollisionMap")
                {
                     int width, height;
                     width = int.Parse(tempnode.Attributes["Width"].Value);
                     height = int.Parse(tempnode.Attributes["Height"].Value);

                 int[,] CollMap = new int[width, height];

                     int y = 0;

                     foreach (XmlNode RowNode in tempnode.ChildNodes)
                     {
                         string row = RowNode.InnerText;
                         row.Trim();
                         row.TrimStart(' ');
                         string[] CellsInRow = row.Split(' ');

                         for (int x = 1; x < CellsInRow.Length; x++)
                         {
                             CollMap[y, (x - 1)] = int.Parse(CellsInRow[x]);
                         }
                         y++;
                     }

                     tempMap.CollisionMap = CollMap;
                }
            }
           
            return tempMap;
        }