public static TiledMapObject FromXML(XmlReader xr) { xr.Read(); int id = int.Parse(xr["id"]); float x = float.Parse(xr["x"]); float y = float.Parse(xr["y"]); string type = xr["type"]; string name = xr["name"]; bool visible = true; float w = 0; float h = 0; float rotation = 0; if (!string.IsNullOrWhiteSpace(xr["width"])) { w = float.Parse(xr["width"]); } if (!string.IsNullOrWhiteSpace(xr["height"])) { h = float.Parse(xr["height"]); } if (!string.IsNullOrWhiteSpace(xr["visible"])) { visible = bool.Parse(xr["visible"]); } if (!string.IsNullOrWhiteSpace(xr["rotation"])) { rotation = float.Parse(xr["rotation"]); } //Normal result without userdefined properties TiledMapObject result = new TiledMapObject(id, new Vector2(x, y), name, type, visible, new Vector2(w, h), rotation); while (xr.Read()) //Read Xml to Properties or the End { if (xr.Name == "properties" && xr.NodeType == XmlNodeType.Element) //Properties { using (StringReader sr = new StringReader(xr.ReadOuterXml())) using (XmlReader r = XmlReader.Create(sr)) result.Properties = TiledProperties.Load(r); } if (xr.Name == "object" && xr.NodeType == XmlNodeType.EndElement) //The End { break; } } return(result); }
internal void Load(XmlReader xr) { List <TiledMapObject> objects = new List <TiledMapObject>(); while (!(xr.NodeType == XmlNodeType.EndElement && xr.Name == "objectgroup") && xr.Read()) { if (xr.Name == "properties") { using (XmlReader r = XmlReader.Create(new StringReader(xr.ReadOuterXml()))) Properties = TiledProperties.Load(r); } if (xr.Name == "object" && xr.NodeType != XmlNodeType.EndElement) { using (XmlReader r = XmlReader.Create(new StringReader(xr.ReadOuterXml()))) objects.Add(TiledMapObject.FromXML(r)); } } Objects = objects.ToArray(); }