diff --git a/src/TiledMap.cs b/src/TiledMap.cs
index 195025f..52abd53 100644
--- a/src/TiledMap.cs
+++ b/src/TiledMap.cs
@@ -129,6 +129,18 @@ public TiledMap(string path)
}
}
+ ///
+ /// Loads a Tiled map in TMX format and parses it
+ ///
+ /// Stream of opened tmx file
+ /// Thrown when the map could not be loaded
+ public TiledMap(Stream stream)
+ {
+ var streamReader = new StreamReader(stream);
+ var content = streamReader.ReadToEnd();
+ ParseXml(content);
+ }
+
///
/// Can be used to parse the content of a TMX map manually instead of loading it using the constructor
///
@@ -292,10 +304,10 @@ private TiledLayer ParseTileLayer(XmlNode node)
if (attrLocked != null) tiledLayer.locked = attrLocked.Value == "1";
if (attrTint != null) tiledLayer.tintcolor = attrTint.Value;
if (attrOpacity != null) tiledLayer.opacity = float.Parse(attrOpacity.Value);
- if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value);
- if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value);
- if (attrParallaxX != null) tiledLayer.offsetX = float.Parse(attrParallaxX.Value);
- if (attrParallaxY != null) tiledLayer.offsetY = float.Parse(attrParallaxY.Value);
+ if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture);
+ if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture);
+ if (attrParallaxX != null) tiledLayer.offsetX = float.Parse(attrParallaxX.Value, CultureInfo.InvariantCulture);
+ if (attrParallaxY != null) tiledLayer.offsetY = float.Parse(attrParallaxY.Value, CultureInfo.InvariantCulture);
if (nodesProperty != null) tiledLayer.properties = ParseProperties(nodesProperty);
ParseTileLayerData(nodeData, ref tiledLayer);
@@ -471,8 +483,8 @@ private TiledLayer ParseObjectLayer(XmlNode node)
if (attrVisible != null) tiledLayer.visible = attrVisible.Value == "1";
if (attrLocked != null) tiledLayer.locked = attrLocked.Value == "1";
if (attrTint != null) tiledLayer.tintcolor = attrTint.Value;
- if (attrOffsetX != null) tiledLayer.offsetX = int.Parse(attrOffsetX.Value);
- if (attrOffsetY != null) tiledLayer.offsetY = int.Parse(attrOffsetY.Value);
+ if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture);
+ if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture);
if (nodesProperty != null) tiledLayer.properties = ParseProperties(nodesProperty);
return tiledLayer;
@@ -497,8 +509,8 @@ private TiledLayer ParseImageLayer(XmlNode node)
if (attrVisible != null) tiledLayer.visible = attrVisible.Value == "1";
if (attrLocked != null) tiledLayer.locked = attrLocked.Value == "1";
if (attrTint != null) tiledLayer.tintcolor = attrTint.Value;
- if (attrOffsetX != null) tiledLayer.offsetX = int.Parse(attrOffsetX.Value);
- if (attrOffsetY != null) tiledLayer.offsetY = int.Parse(attrOffsetY.Value);
+ if (attrOffsetX != null) tiledLayer.offsetX = float.Parse(attrOffsetX.Value, CultureInfo.InvariantCulture);
+ if (attrOffsetY != null) tiledLayer.offsetY = float.Parse(attrOffsetY.Value, CultureInfo.InvariantCulture);
if (nodesProperty != null) tiledLayer.properties = ParseProperties(nodesProperty);
if (nodeImage != null) tiledLayer.image = ParseImage(nodeImage);
@@ -817,4 +829,4 @@ public bool IsTileFlippedDiagonal(TiledLayer layer, int dataIndex)
return (layer.dataRotationFlags[dataIndex] & (FLIPPED_DIAGONALLY_FLAG >> SHIFT_FLIP_FLAG_TO_BYTE)) > 0;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/TiledTileset.cs b/src/TiledTileset.cs
index db59f2e..b3a4d0f 100644
--- a/src/TiledTileset.cs
+++ b/src/TiledTileset.cs
@@ -90,6 +90,18 @@ public TiledTileset(string path)
}
}
+ ///
+ /// Loads a tileset in TSX format and parses it
+ ///
+ /// The file stream of the TSX file
+ /// Thrown when the file could not be parsed
+ public TiledTileset(Stream stream)
+ {
+ var streamReader = new StreamReader(stream);
+ var content = streamReader.ReadToEnd();
+ ParseXml(content);
+ }
+
///
/// Can be used to parse the content of a TSX tileset manually instead of loading it using the constructor
///