/// <summary>
        /// Creates a grid collider from any TiledTileLayer. Each tile that have an image set it will 
        /// create a collider the size of the tile.
        /// </summary>
        /// <param name="tileLayer">
        /// The tile layer with all the information needed to generate a grid collider.
        /// </param>
        /// <param name="tags">
        /// The tags that will be applied to all of the colliders in the grid collider.
        /// </param>
        /// <returns>
        /// A grid collider with a collider at each position where a tile is set.
        /// </returns>
        public GridCollider CreateGridCollider(TiledTileLayer tileLayer, params int[] tags)
        {
            var grid = new GridCollider(PixelWidth, PixelHeight, TileWidth, TileHeight, tags);

            foreach(var tile in tileLayer.Tiles)
            {
                if(tile.Gid > 0)
                {
                    grid.SetTile(tile.X, tile.Y);
                }
            }

            return grid;
        }
        public TiledProject(string source)
        {
            CheckExists(source);

            Source = source;

            var xmlDoc = new XmlDocument();
            xmlDoc.Load(Source);
            var map = xmlDoc.GetElementsByTagName("map")[0];
            Width = map.AttributeInt("width");
            Height = map.AttributeInt("height");
            TileWidth = map.AttributeInt("tilewidth");
            TileHeight = map.AttributeInt("tileheight");

            LoadProperties(map);
            LoadTilesets(xmlDoc);

            var nodes = map.ChildNodes;
            foreach(XmlElement node in nodes)
            {
                var tag = node.Name;

                if(tag == "layer")
                {
                    var layer = new TiledTileLayer(node);
                    Layers.Add(layer);
                }
                else if(tag == "objectgroup")
                {
                    var layer = new TiledObjectGroup(node);
                    Layers.Add(layer);
                }
            }
        }
        /// <summary>
        /// Creates an Otter Tilemap from the data loaded from the Tiled Map Editor file.
        /// </summary>
        /// <param name="tileLayer">
        /// The Tiled Map Editor Layer to be turned into an Otter tilemap.
        /// </param>
        /// <returns>
        /// The Otter tilemap representation of the Tiled Map Editor Layer.
        /// </returns>
        public Tilemap CreateTilemap(TiledTileLayer tileLayer)
        {
            var path = GetTilemapPath(TileSets.First().ImageSource);

            CheckExists(path);

            var tilemap = new Tilemap(path, PixelWidth, PixelHeight, TileWidth, TileHeight);
            tilemap.DefaultLayerName = tileLayer.Name;

            var layerName = tileLayer.Name;
            tilemap.AddLayer(layerName, 1);

            for(var x = 0; x < Width; x++)
            {
                for(var y = 0; y < Height; y++)
                {
                    var i = y * Width + x;
                    var gid = (int)tileLayer.Tiles[i].Gid;
                    if(gid > 0)
                    {
                        tilemap.SetTile(x, y, gid - 1, layerName);
                    }
                }

            }

            return tilemap;
        }