5 using System.Collections.Generic;
8 using System.IO.Compression;
14 public string Name {
get;
private set;}
18 public List<TmxLayerTile>
Tiles {
get;
private set;}
21 public TmxLayer(XElement xLayer,
int width,
int height)
23 Name = (string)xLayer.Attribute(
"name");
24 Opacity = (
double?)xLayer.Attribute(
"opacity") ?? 1.0;
25 Visible = (
bool?)xLayer.Attribute(
"visible") ??
true;
27 var xData = xLayer.Element(
"data");
28 var encoding = (string)xData.Attribute(
"encoding");
30 Tiles =
new List<TmxLayerTile>();
31 if (encoding ==
"base64")
34 var stream = decodedStream.Data;
36 using (var br =
new BinaryReader(stream))
37 for (
int j = 0; j < height; j++)
38 for (
int i = 0; i < width; i++)
41 else if (encoding ==
"csv")
43 var csvData = (string)xData.Value;
45 foreach (var s in csvData.Split(
','))
47 var gid = uint.Parse(s.Trim());
54 else if (encoding == null)
57 foreach (var e
in xData.Elements(
"tile"))
59 var gid = (uint)e.Attribute(
"gid");
66 else throw new Exception(
"TmxLayer: Unknown encoding.");
75 const uint FLIPPED_HORIZONTALLY_FLAG = 0x80000000;
76 const uint FLIPPED_VERTICALLY_FLAG = 0x40000000;
77 const uint FLIPPED_DIAGONALLY_FLAG = 0x20000000;
79 public int Gid {
get;
private set;}
80 public int X {
get;
private set;}
81 public int Y {
get;
private set;}
95 flip = (rawGid & FLIPPED_HORIZONTALLY_FLAG) != 0;
98 flip = (rawGid & FLIPPED_VERTICALLY_FLAG) != 0;
101 flip = (rawGid & FLIPPED_DIAGONALLY_FLAG) != 0;
105 rawGid &= ~(FLIPPED_HORIZONTALLY_FLAG |
106 FLIPPED_VERTICALLY_FLAG |
107 FLIPPED_DIAGONALLY_FLAG);
int Gid
Global tileset ID.
double Opacity
Alpha transparency of layer.
PropertyDict Properties
User-defined layer properties.
bool Visible
True if layer is visible.
bool HorizontalFlip
Horizontally flipped tile image.
List< TmxLayerTile > Tiles
List of layer map tiles to be rendered.
bool DiagonalFlip
Diagonally flipped tile image along top left/bottom right axis.
Tile elements of a layer map.
bool VerticalFlip
Vertically flipped tile image.
int X
X (rightward) position of tile.
TmxLayer(XElement xLayer, int width, int height)
Tile map layer constructor.
TmxLayerTile(uint id, int x, int y)
Layer tile constructor.
int Y
Y (downward) position of tile.
User-defined property list.