diff --git a/TiledCSPlus/TiledMap.cs b/TiledCSPlus/TiledMap.cs
index 690c96c..ad0a5ad 100644
--- a/TiledCSPlus/TiledMap.cs
+++ b/TiledCSPlus/TiledMap.cs
@@ -345,7 +345,7 @@ private TiledLayer ParseLayer(XmlNode node, TiledLayerType type)
Name = node.Attributes["name"].Value,
Visible = true,
Opacity = 1.0f,
- Parrallax = new Vector2(1.0f, 1.0f)
+ Parallax = new Vector2(1.0f, 1.0f)
};
if(attrWidth != null) tiledLayer.Width = int.Parse(attrWidth.Value);
@@ -355,13 +355,19 @@ private TiledLayer ParseLayer(XmlNode node, TiledLayerType type)
if(attrTint != null) tiledLayer.TintColor = ParseColor(attrTint.Value);
if(attrClass != null) tiledLayer.Class = attrClass.Value;
if(attrOpacity != null) tiledLayer.Opacity = float.Parse(attrOpacity.Value, CultureInfo.InvariantCulture);
- if(attrOffsetX != null || attrOffsetY != null) tiledLayer.Offset = new Vector2(0, 0);
- if(attrOffsetX != null) tiledLayer.Offset.X = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture);
- if(attrOffsetY != null) tiledLayer.Offset.Y = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture);
+
+ Vector2 offset = new Vector2();
+ if(attrOffsetX != null) offset.X = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture);
+ if(attrOffsetY != null) offset.Y = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture);
+ if(attrOffsetX != null || attrOffsetY != null) tiledLayer.Offset = offset;
+
+ Vector2 parallax = new Vector2();
if(attrParallaxX != null)
- tiledLayer.Parrallax.X = float.Parse(attrParallaxX.Value, CultureInfo.InvariantCulture);
+ parallax.X = float.Parse(attrParallaxX.Value, CultureInfo.InvariantCulture);
if(attrParallaxY != null)
- tiledLayer.Parrallax.Y = float.Parse(attrParallaxY.Value, CultureInfo.InvariantCulture);
+ parallax.Y = float.Parse(attrParallaxY.Value, CultureInfo.InvariantCulture);
+ if (attrParallaxX != null || attrParallaxY != null) tiledLayer.Parallax = parallax;
+
if(nodesProperty != null) tiledLayer.Properties = ParseProperties(nodesProperty);
if(type == TiledLayerType.TileLayer)
@@ -631,12 +637,14 @@ private TiledObject[] ParseObjects(XmlNodeList nodeList)
Name = node.Attributes["name"]?.Value,
Class = MapVersion == "1.9" ? node.Attributes["class"]?.Value : node.Attributes["type"]?.Value,
Position = new Vector2(float.Parse(node.Attributes["x"].Value, CultureInfo.InvariantCulture),
- float.Parse(node.Attributes["y"].Value, CultureInfo.InvariantCulture))
+ float.Parse(node.Attributes["y"].Value, CultureInfo.InvariantCulture)),
+ Type = TiledObjectType.Rectangular
};
if(attrGid != null)
{
ParseObjectGid(ref obj, attrGid.Value);
+ obj.Type = TiledObjectType.Tile;
}
if(nodesProperty != null)
@@ -659,6 +667,7 @@ private TiledObject[] ParseObjects(XmlNodeList nodeList)
}
obj.Polygon = polygon;
+ obj.Type = TiledObjectType.Polygon;
}
if (nodePolyline != null)
@@ -676,29 +685,32 @@ private TiledObject[] ParseObjects(XmlNodeList nodeList)
}
obj.Polyline = polyline;
+ obj.Type = TiledObjectType.Polyline;
}
if(nodeEllipse != null)
{
- obj.Ellipse = new TiledEllipse();
+ obj.Type = TiledObjectType.Eclipse;
}
if(nodePoint != null)
{
- obj.Point = new TiledPoint();
+ obj.Type = TiledObjectType.Point;
}
- if(node.Attributes["width"] != null || node.Attributes["height"] != null) obj.Size = new Size(0, 0);
+ Vector2 size = new Vector2();
if(node.Attributes["width"] != null)
{
- obj.Size.Width = float.Parse(node.Attributes["width"].Value, CultureInfo.InvariantCulture);
+ size.X = float.Parse(node.Attributes["width"].Value, CultureInfo.InvariantCulture);
}
if(node.Attributes["height"] != null)
{
- obj.Size.Height = float.Parse(node.Attributes["height"].Value, CultureInfo.InvariantCulture);
+ size.Y = float.Parse(node.Attributes["height"].Value, CultureInfo.InvariantCulture);
}
+ if (node.Attributes["width"] != null || node.Attributes["height"] != null) obj.Size = size;
+
if(node.Attributes["rotation"] != null)
{
obj.Rotation = float.Parse(node.Attributes["rotation"].Value, CultureInfo.InvariantCulture);
diff --git a/TiledCSPlus/TiledModels.cs b/TiledCSPlus/TiledModels.cs
index 12d9332..4915940 100644
--- a/TiledCSPlus/TiledModels.cs
+++ b/TiledCSPlus/TiledModels.cs
@@ -5,26 +5,6 @@
namespace TiledCSPlus
{
- ///
- /// Represents a size
- ///
- public class Size : IEquatable
- {
- public float Width { get; internal set; }
- public float Height { get; internal set; }
-
- public Size(float width = 0, float height = 0)
- {
- this.Width = width;
- this.Height = height;
- }
-
- public bool Equals(Size other)
- {
- return Width.Equals(other.Width) && Height.Equals(other.Height);
- }
- }
-
///
/// Represents an element within the Tilesets array of a TiledMap object
///
@@ -115,12 +95,12 @@ public class TiledLayer
///
/// Layer offset
///
- public Vector2 Offset;
+ public Vector2 Offset { get; internal set; }
///
/// Parallax position
///
- public Vector2 Parrallax;
+ public Vector2 Parallax { get; internal set; }
///
/// The layer opacity
@@ -200,7 +180,12 @@ public class TiledObject
///
/// Object's size in pixels
///
- public Size Size { get; internal set; }
+ public Vector2 Size { get; internal set; }
+
+ ///
+ /// Object type
+ ///
+ public TiledObjectType Type { get; internal set; }
///
/// The tileset gid when the object is linked to a tile
@@ -230,16 +215,6 @@ public class TiledObject
/// If an object was set to a polyline shape, this property will be set and can be used to access the polyline's data
///
public TiledPolyline Polyline { get; internal set; }
-
- ///
- /// If an object was set to a point shape, this property will be set
- ///
- public TiledPoint Point { get; internal set; }
-
- ///
- /// If an object was set to an ellipse shape, this property will be set
- ///
- public TiledEllipse Ellipse { get; internal set; }
}
///
@@ -264,20 +239,6 @@ public class TiledPolyline
public Vector2[] Points { get; internal set; }
}
- ///
- /// Represents a point shape
- ///
- public class TiledPoint
- {
- }
-
- ///
- /// Represents an ellipse shape
- ///
- public class TiledEllipse
- {
- }
-
///
/// Represents a tile within a tileset
///
@@ -339,7 +300,7 @@ public class TiledImage
///
/// The image source path
///
- public string Source;
+ public string Source { get; internal set; }
}
///
@@ -588,4 +549,40 @@ public class TiledTerrainSetTile
///
public int TopLeft { get; internal set; }
}
+
+ ///
+ /// Represents object types in Tiled
+ ///
+ public enum TiledObjectType
+ {
+ ///
+ /// Point object type
+ ///
+ Point,
+
+ ///
+ /// Eclipse object type
+ ///
+ Eclipse,
+
+ ///
+ /// Polygon object type
+ ///
+ Polygon,
+
+ ///
+ /// Polyline object type (used when polygon object is not closed)
+ ///
+ Polyline,
+
+ ///
+ /// Tile object type
+ ///
+ Tile,
+
+ ///
+ /// Rectangular object type
+ ///
+ Rectangular
+ }
}
\ No newline at end of file
diff --git a/TiledCSPlus/TiledTileset.cs b/TiledCSPlus/TiledTileset.cs
index eef180d..ee7572c 100644
--- a/TiledCSPlus/TiledTileset.cs
+++ b/TiledCSPlus/TiledTileset.cs
@@ -311,7 +311,8 @@ private TiledObject[] ParseObjects(XmlNodeList nodeList)
Class = TilesetVersion == "1.9" ? node.Attributes["class"]?.Value : node.Attributes["type"]?.Value,
Gid = int.Parse(node.Attributes["gid"]?.Value ?? "0"),
Position = new Vector2(float.Parse(node.Attributes["x"].Value, CultureInfo.InvariantCulture),
- float.Parse(node.Attributes["y"].Value, CultureInfo.InvariantCulture))
+ float.Parse(node.Attributes["y"].Value, CultureInfo.InvariantCulture)),
+ Type = TiledObjectType.Rectangular
};
if(nodesProperty != null)
@@ -334,6 +335,7 @@ private TiledObject[] ParseObjects(XmlNodeList nodeList)
}
obj.Polygon = polygon;
+ obj.Type = TiledObjectType.Polygon;
}
if (nodePolyline != null)
@@ -351,28 +353,30 @@ private TiledObject[] ParseObjects(XmlNodeList nodeList)
}
obj.Polyline = polyline;
+ obj.Type = TiledObjectType.Polyline;
}
if(nodeEllipse != null)
{
- obj.Ellipse = new TiledEllipse();
+ obj.Type = TiledObjectType.Eclipse;
}
if(nodePoint != null)
{
- obj.Point = new TiledPoint();
+ obj.Type = TiledObjectType.Point;
}
- if(node.Attributes["width"] != null || node.Attributes["height"] != null) obj.Size = new Size();
+ Vector2 size = new Vector2();
if(node.Attributes["width"] != null)
{
- obj.Size.Width = float.Parse(node.Attributes["width"].Value, CultureInfo.InvariantCulture);
+ size.X = float.Parse(node.Attributes["width"].Value, CultureInfo.InvariantCulture);
}
if(node.Attributes["height"] != null)
{
- obj.Size.Height = float.Parse(node.Attributes["height"].Value, CultureInfo.InvariantCulture);
+ size.Y = float.Parse(node.Attributes["height"].Value, CultureInfo.InvariantCulture);
}
+ if (node.Attributes["width"] != null || node.Attributes["height"] != null) obj.Size = size;
if(node.Attributes["rotation"] != null)
{