TiledSharp  0.9.1 r0
A .NET C# library for importing Tiled TMX tile maps
 All Classes Namespaces Files Functions Variables Enumerations Properties Pages
Map.cs
Go to the documentation of this file.
1 // Distributed as part of TiledSharp, Copyright 2012 Marshall Ward
2 // Licensed under the Apache License, Version 2.0
3 // http://www.apache.org/licenses/LICENSE-2.0
4 using System;
5 using System.Xml.Linq;
6 using System.Globalization;
7 
8 namespace TiledSharp
9 {
10  public class TmxMap : TmxDocument
11  {
12  public string Version {get; private set;}
13  public OrientationType Orientation {get; private set;}
14  public int Width {get; private set;}
15  public int Height {get; private set;}
16  public int TileWidth {get; private set;}
17  public int TileHeight {get; private set;}
18  public TmxColor BackgroundColor {get; private set;}
19 
20  public TmxList<TmxTileset> Tilesets {get; private set;}
21  public TmxList<TmxLayer> Layers {get; private set;}
22  public TmxList<TmxObjectGroup> ObjectGroups {get; private set;}
23  public TmxList<TmxImageLayer> ImageLayers {get; private set;}
24  public PropertyDict Properties {get; private set;}
25 
26  public TmxMap(string filename)
27  {
28  XDocument xDoc = ReadXml(filename);
29  var xMap = xDoc.Element("map");
30 
31  Version = (string)xMap.Attribute("version");
32  Orientation = (OrientationType) Enum.Parse(
33  typeof(OrientationType),
34  xMap.Attribute("orientation").Value,
35  true);
36  Width = (int)xMap.Attribute("width");
37  Height = (int)xMap.Attribute("height");
38  TileWidth = (int)xMap.Attribute("tilewidth");
39  TileHeight = (int)xMap.Attribute("tileheight");
40  BackgroundColor = new TmxColor(xMap.Attribute("backgroundcolor"));
41 
42  Tilesets = new TmxList<TmxTileset>();
43  foreach (var e in xMap.Elements("tileset"))
44  Tilesets.Add(new TmxTileset(e, TmxDirectory));
45 
46  Layers = new TmxList<TmxLayer>();
47  foreach (var e in xMap.Elements("layer"))
48  Layers.Add(new TmxLayer(e, Width, Height));
49 
50  ObjectGroups = new TmxList<TmxObjectGroup>();
51  foreach (var e in xMap.Elements("objectgroup"))
52  ObjectGroups.Add(new TmxObjectGroup(e));
53 
54  ImageLayers = new TmxList<TmxImageLayer>();
55  foreach (var e in xMap.Elements("imagelayer"))
57 
58  Properties = new PropertyDict(xMap.Element("properties"));
59  }
60 
61  public enum OrientationType : byte
62  {
63  Orthogonal,
64  Isometric,
65  Staggered
66  }
67  }
68 }
int TileHeight
Pixel height of (smallest) tiles.
Definition: Map.cs:17
RGB color components.
Definition: TiledCore.cs:136
TmxColor BackgroundColor
Map background color.
Definition: Map.cs:18
TMX document importer.
Definition: TiledCore.cs:16
int TileWidth
Pixel width of (smallest) tiles.
Definition: Map.cs:16
PropertyDict Properties
User-defined map properties.
Definition: Map.cs:24
string TmxDirectory
Parent directory of TMX file.
Definition: TiledCore.cs:18
string Version
TMX format version.
Definition: Map.cs:12
External image layer.
Definition: ImageLayer.cs:9
int Height
Map height in tiles.
Definition: Map.cs:15
XDocument ReadXml(string filepath)
Parse XML content of TMX file.
Definition: TiledCore.cs:20
Layer tile maps.
Definition: Layer.cs:12
TmxList< TmxObjectGroup > ObjectGroups
List of map object layers.
Definition: Map.cs:22
Tilesets for a TMX Map.
Definition: Tileset.cs:11
TmxList< TmxLayer > Layers
List of map layers.
Definition: Map.cs:21
TmxMap(string filename)
Map constructor.
Definition: Map.cs:26
Map object layer.
Definition: ObjectGroup.cs:11
int Width
Map width in tiles.
Definition: Map.cs:14
OrientationType Orientation
Map orientation.
Definition: Map.cs:13
TmxList< TmxTileset > Tilesets
List of map tilesets.
Definition: Map.cs:20
User-defined property list.
Definition: TiledCore.cs:90
Container class for TMX map file.
Definition: Map.cs:10
OrientationType
Map orientation type.
Definition: Map.cs:61
TmxList< TmxImageLayer > ImageLayers
List of background image layers.
Definition: Map.cs:23