예제 #1
0
		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"));
		}
예제 #2
0
		public TmxLayer(TmxMap map, XElement xLayer, int width, int height)
			: this(map) {
			Name = (string)xLayer.Attribute("name");
			Width = (int)xLayer.Attribute("width");
			Height = (int)xLayer.Attribute("height");

			var xOpacity = xLayer.Attribute("opacity");
			Opacity = xOpacity == null ? 1.0 : (double)xOpacity;

			var xVisible = xLayer.Attribute("visible");
			Visible = xVisible == null || (bool)xVisible;

			var xData = xLayer.Element("data");
			var encoding = (string)xData.Attribute("encoding");

			Tiles = new List<TmxLayerTile>();
			if (encoding == "base64") {
				var base64data = Convert.FromBase64String((string)xData.Value);
				Stream stream = new MemoryStream(base64data, false);

				var compression = (string)xData.Attribute("compression");
				/*
				if (compression == "gzip")
					stream = new GZipStream(stream, CompressionMode.Decompress,
											false);
				else if (compression == "zlib")
					stream = new Ionic.Zlib.ZlibStream(stream,
								Ionic.Zlib.CompressionMode.Decompress, false);
				else 
				*/
				if (compression != null)
					throw new Exception("Tiled: Unknown compression.");

				using (stream)
				using (var br = new BinaryReader(stream))
					for (int j = 0; j < height; j++)
						for (int i = 0; i < width; i++)
							Tiles.Add(new TmxLayerTile(this, br.ReadUInt32(), i, j));
			} else if (encoding == "csv") {
				var csvData = (string)xData.Value;
				int k = 0;
				foreach (var s in csvData.Split(',')) {
					var gid = uint.Parse(s.Trim());
					var x = k % width;
					var y = k / width;
					Tiles.Add(new TmxLayerTile(this, gid, x, y));
					k++;
				}
			} else if (encoding == null) {
				int k = 0;
				foreach (var e in xData.Elements("tile")) {
					var gid = (uint)e.Attribute("gid");
					var x = k % width;
					var y = k / width;
					Tiles.Add(new TmxLayerTile(this, gid, x, y));
					k++;
				}
			} else throw new Exception("Tiled: Unknown encoding.");

			Properties = new PropertyDict(xLayer.Element("properties"));
		}
예제 #3
0
		protected TmxLayer(TmxMap map) {
			ParentMap = map;
		}
예제 #4
0
		/// <exception cref="Exception">Failed to load interface</exception>
		public override void LoadContent() {
			base.LoadContent();

			mMap = new TmxMap("Tests/Tmx/Maps/test-inhouse.tmx");
			mGridTexture = DrawHelper.Rect2Texture(ScreenManager.GameCamera.TileWidth, ScreenManager.GameCamera.TileHeight, 1, Color.White);
		}
예제 #5
0
        public TmxLayer(TmxMap map, XElement xLayer, int width, int height)
            : this(map) {
            Name   = (string)xLayer.Attribute("name");
            Width  = (int)xLayer.Attribute("width");
            Height = (int)xLayer.Attribute("height");

            var xOpacity = xLayer.Attribute("opacity");
            Opacity = xOpacity == null ? 1.0 : (double)xOpacity;

            var xVisible = xLayer.Attribute("visible");
            Visible = xVisible == null || (bool)xVisible;

            var xData    = xLayer.Element("data");
            var encoding = (string)xData.Attribute("encoding");

            Tiles = new List <TmxLayerTile>();
            if (encoding == "base64")
            {
                var    base64data = Convert.FromBase64String((string)xData.Value);
                Stream stream     = new MemoryStream(base64data, false);

                var compression = (string)xData.Attribute("compression");

                /*
                 * if (compression == "gzip")
                 *      stream = new GZipStream(stream, CompressionMode.Decompress,
                 *                                                      false);
                 * else if (compression == "zlib")
                 *      stream = new Ionic.Zlib.ZlibStream(stream,
                 *                              Ionic.Zlib.CompressionMode.Decompress, false);
                 * else
                 */
                if (compression != null)
                {
                    throw new Exception("Tiled: Unknown compression.");
                }

                using (stream)
                    using (var br = new BinaryReader(stream))
                        for (int j = 0; j < height; j++)
                        {
                            for (int i = 0; i < width; i++)
                            {
                                Tiles.Add(new TmxLayerTile(this, br.ReadUInt32(), i, j));
                            }
                        }
            }
            else if (encoding == "csv")
            {
                var csvData = (string)xData.Value;
                int k       = 0;
                foreach (var s in csvData.Split(','))
                {
                    var gid = uint.Parse(s.Trim());
                    var x   = k % width;
                    var y   = k / width;
                    Tiles.Add(new TmxLayerTile(this, gid, x, y));
                    k++;
                }
            }
            else if (encoding == null)
            {
                int k = 0;
                foreach (var e in xData.Elements("tile"))
                {
                    var gid = (uint)e.Attribute("gid");
                    var x   = k % width;
                    var y   = k / width;
                    Tiles.Add(new TmxLayerTile(this, gid, x, y));
                    k++;
                }
            }
            else
            {
                throw new Exception("Tiled: Unknown encoding.");
            }

            Properties = new PropertyDict(xLayer.Element("properties"));
        }
예제 #6
0
 protected TmxLayer(TmxMap map)
 {
     ParentMap = map;
 }