public TmxImageLayer(TmxMap map, XElement xImageLayer, string tmxDir = "") : base(map) { Name = (string)xImageLayer.Attribute("name"); Width = (int)xImageLayer.Attribute("width"); Height = (int)xImageLayer.Attribute("height"); var xVisible = xImageLayer.Attribute("visible"); Visible = xVisible == null || (bool)xVisible; var xOpacity = xImageLayer.Attribute("opacity"); Opacity = xOpacity == null ? 1.0 : (double)xOpacity; Image = new TmxImage(xImageLayer.Element("image"), tmxDir); Properties = new PropertyDict(xImageLayer.Element("properties")); }
// TMX tileset element constructor public TmxTileset(XElement xTileset, string tmxDir = null) { var xFirstGid = xTileset.Attribute("firstgid"); var source = (string)xTileset.Attribute("source"); if (source != null) { // Prepend the parent TMX directory if necessary source = Path.Combine(tmxDir, source); // source is always preceded by firstgid FirstGid = (int)xFirstGid; // Everything else is in the TSX file var xDocTileset = ReadXml(source); var ts = new TmxTileset(xDocTileset, TmxDirectory); Name = ts.Name; TileWidth = ts.TileWidth; TileHeight = ts.TileHeight; Spacing = ts.Spacing; Margin = ts.Margin; Image = ts.Image; Tiles = ts.Tiles; } else { // firstgid is always in TMX, but not TSX if (xFirstGid != null) { FirstGid = (int)xFirstGid; } Name = (string)xTileset.Attribute("name"); Image = new TmxImage(xTileset.Element("image"), tmxDir); TileWidth = (int)xTileset.Attribute("tilewidth"); TileHeight = (int)xTileset.Attribute("tileheight"); var xSpacing = xTileset.Attribute("spacing"); if (xSpacing == null) { Spacing = 0; } else { Spacing = (int)xSpacing; } var xMargin = xTileset.Attribute("margin"); if (xMargin == null) { Margin = 0; } else { Margin = (int)xMargin; } Tiles = new Dictionary <int, PropertyDict>(); foreach (var xml_tile in xTileset.Elements("tile")) { var id = (int)xml_tile.Attribute("id"); var xProp = xml_tile.Element("properties"); Tiles.Add(id, new PropertyDict(xProp)); } } }