public static TexturedSolid FromXml(XElement xEle, LazyLoadingMaterialDictionary materials) { TexturedSolid obj = new TexturedSolid(); // get pos from xml obj.Position = new Vector2().FromXml(xEle.Element("Position")); // get size from xml obj.Size = new Vector2().FromXml(xEle.Element("Size")); // get z-index obj.ZIndex = sbyte.Parse(xEle.Element("Z-Index").Value); // get texture from lazy loading dictionary provided by the LevelManager obj.Material = materials[xEle.Element("TexturePath").Value]; // get rotation obj.Rotation = float.Parse(xEle.Element("Rotation").Value, CultureInfo.InvariantCulture.NumberFormat); // get opacity obj.Opacity = float.Parse(xEle.Element("Opacity").Value, CultureInfo.InvariantCulture.NumberFormat); // get parallax multiplier. If no parallax multiplier defined set to 1 obj.ParallaxMultiplier = float.Parse(xEle.Element("Parallax")?.Value ?? "1", CultureInfo.InvariantCulture); return(obj); }
public override XElement ToXml(LazyLoadingMaterialDictionary materialDictionary) { if (Material != null) { materialDictionary.LoadMaterial(Material.Path); } XElement?texPathXEle = Material != null ? new XElement("TexturePath", materialDictionary.GetTexturePathByName(Material.Name)) : null; XElement result = new XElement(this.GetType().Name, Position.ToXml("Position"), Size.ToXml("Size"), texPathXEle, new XElement("Rotation", Rotation.ToString(CultureInfo.InvariantCulture)), new XElement("Opacity", Opacity.ToString(CultureInfo.InvariantCulture)), new XElement("Z-Index", ZIndex.ToString(CultureInfo.InvariantCulture)) ); if (!string.IsNullOrEmpty(Id)) { result.Add(new XAttribute("Id", Id)); } if (!string.IsNullOrEmpty(Class)) { result.Add(new XAttribute("Class", Class)); } return(result); }
public static Player FromXml(XElement xEle, LazyLoadingMaterialDictionary materials) { return(new SidescrollingPlayer() { Position = new Vector2().FromXml(xEle.Element("Position")), Size = new Vector2().FromXml(xEle.Element("Size")), Material = xEle.Element("TexturePath") != null ? materials[xEle.Element("TexturePath").Value] : null, ZIndex = sbyte.Parse(xEle.Element("Z-Index").Value), Rotation = float.Parse(xEle.Element("Rotation").Value, CultureInfo.InvariantCulture.NumberFormat), Opacity = float.Parse(xEle.Element("Opacity").Value, CultureInfo.InvariantCulture.NumberFormat), }); }
public abstract XElement ToXml(LazyLoadingMaterialDictionary materialDictionary);