示例#1
0
        protected override void ReadXml(XElement xTile)
        {
            Id          = (int)xTile.Attribute("id");
            Type        = (string)xTile.Attribute("type");
            Terrain     = (string)xTile.Attribute("terrain") ?? "";
            Probability = (float?)xTile.Attribute("probability") ?? 1f;

            var properties = xTile.Element("properties");

            Properties = ReadProperties(properties);

            var image = xTile.Element("image");

            if (image != null)
            {
                EmbeddedImage = new TiledImage(image);
            }

            var objects = xTile.Element("objectgroup");

            if (objects != null)
            {
                Objects = new TiledObjectGroup(objects);
            }

            var animation = xTile.Element("animation");

            if (animation != null)
            {
                foreach (var frame in animation.Elements("frame"))
                {
                    Animation.Add(new TiledFrame(frame));
                }
            }
        }
示例#2
0
        protected override void ReadXml(XElement xTileset)
        {
            var firstGid = xTileset.Attribute("firstgid");

            if (firstGid != null)
            {
                FirstGid = (int)firstGid;
            }

            Source = (string)xTileset.Attribute("source");
            if (Source != null)
            {
                Source = System.IO.Path.Combine(xTileset.BaseUri, "../", Source);
                var ts = new TiledTileset(Source);
                ReadFromSource(ts);
            }
            else
            {
                Name       = (string)xTileset.Attribute("name");
                TileWidth  = (int)xTileset.Attribute("tilewidth");
                TileHeight = (int)xTileset.Attribute("tileheight");

                var spacing = xTileset.Attribute("spacing");
                if (spacing != null)
                {
                    Spacing = (int)spacing;
                }

                var margin = xTileset.Attribute("margin");
                if (margin != null)
                {
                    Margin = (int)margin;
                }

                TileCount = (int)xTileset.Attribute("tilecount");
                Columns   = (int)xTileset.Attribute("columns");

                var offset = xTileset.Element("tileoffset");
                if (offset != null)
                {
                    Offset = new TiledOffset(offset);
                }

                var grid = xTileset.Element("grid");
                if (grid != null)
                {
                    Grid = new TiledGrid(grid);
                }

                Properties = ReadProperties(xTileset.Element("properties"));

                var image = xTileset.Element("image");
                if (image != null)
                {
                    Image = new TiledImage(image);
                }

                TerrainTypes = new List <TiledTerrain>();
                var xTerrainTypes = xTileset.Element("terraintypes");
                if (xTerrainTypes != null)
                {
                    foreach (var xTerrain in xTerrainTypes.Elements("terrain"))
                    {
                        TerrainTypes.Add(new TiledTerrain(xTerrain));
                    }
                }

                Tiles = new List <TiledTile>();
                foreach (var xTile in xTileset.Elements("tile"))
                {
                    Tiles.Add(new TiledTile(xTile));
                }

                WangSets = new List <WangSet>();
                var xWangSets = xTileset.Element("wangsets");
                if (xWangSets != null)
                {
                    foreach (var xWangSet in xWangSets.Elements("wangset"))
                    {
                        WangSets.Add(new WangSet(xWangSet));
                    }
                }
            }
        }