/// <summary> /// Loads animation settings from an xml file. /// </summary> private void LoadAnimationFromXML() { XDocument doc = XDocument.Load("Content/Textures/AnimationsDefinition.xml"); XName name = XName.Get("Definition"); var definitions = doc.Document.Descendants(name); // Loop over all definitions in the XML foreach (XElement animationDefinition in definitions) { // Get the name of the animation string animationAlias = animationDefinition.Attribute("Alias").Value; Texture2D texture = ScreenManager.Game.Content.Load <Texture2D>(animationDefinition.Attribute("SheetName").Value); // Get the frame size (width & height) Point frameSize = new Point(); frameSize.X = int.Parse(animationDefinition.Attribute("FrameWidth").Value); frameSize.Y = int.Parse(animationDefinition.Attribute("FrameHeight").Value); // Get the frames sheet dimensions Point sheetSize = new Point(); sheetSize.X = int.Parse(animationDefinition.Attribute("SheetColumns").Value); sheetSize.Y = int.Parse(animationDefinition.Attribute("SheetRows").Value); ScaledAnimation animation = new ScaledAnimation(texture, frameSize, sheetSize); // Checks for sub-animation definition if (animationDefinition.Element("SubDefinition") != null) { int startFrame = int.Parse( animationDefinition.Element("SubDefinition").Attribute("StartFrame").Value); int endFrame = int.Parse (animationDefinition.Element("SubDefinition").Attribute("EndFrame").Value); animation.SetSubAnimation(startFrame, endFrame); } if (animationDefinition.Attribute("Speed") != null) { animation.SetFrameInterval(TimeSpan.FromMilliseconds( double.Parse(animationDefinition.Attribute("Speed").Value))); } // If the definition has an offset defined - it should be // rendered relative to some element/animation if (null != animationDefinition.Attribute("OffsetX") && null != animationDefinition.Attribute("OffsetY")) { animation.Offset = new Vector2(int.Parse(animationDefinition.Attribute("OffsetX").Value), int.Parse(animationDefinition.Attribute("OffsetY").Value)); } animations.Add(animationAlias, animation); } }
/// <summary> /// Loads animation settings from an xml file. /// </summary> private void LoadAnimationFromXML() { XDocument doc = XDocument.Load("Content/Textures/AnimationsDefinition.xml"); XName name = XName.Get("Definition"); var definitions = doc.Document.Descendants(name); // Loop over all definitions in the XML foreach (XElement animationDefinition in definitions) { // Get the name of the animation string animationAlias = animationDefinition.Attribute("Alias").Value; Texture2D texture = ScreenManager.Game.Content.Load<Texture2D>(animationDefinition.Attribute("SheetName").Value); // Get the frame size (width & height) Point frameSize = new Point(); frameSize.X = int.Parse(animationDefinition.Attribute("FrameWidth").Value); frameSize.Y = int.Parse(animationDefinition.Attribute("FrameHeight").Value); // Get the frames sheet dimensions Point sheetSize = new Point(); sheetSize.X = int.Parse(animationDefinition.Attribute("SheetColumns").Value); sheetSize.Y = int.Parse(animationDefinition.Attribute("SheetRows").Value); ScaledAnimation animation = new ScaledAnimation(texture, frameSize, sheetSize); // Checks for sub-animation definition if (animationDefinition.Element("SubDefinition") != null) { int startFrame = int.Parse( animationDefinition.Element("SubDefinition").Attribute("StartFrame").Value); int endFrame = int.Parse (animationDefinition.Element("SubDefinition").Attribute("EndFrame").Value); animation.SetSubAnimation(startFrame, endFrame); } if (animationDefinition.Attribute("Speed") != null) { animation.SetFrameInterval(TimeSpan.FromMilliseconds( double.Parse(animationDefinition.Attribute("Speed").Value))); } // If the definition has an offset defined - it should be // rendered relative to some element/animation if (null != animationDefinition.Attribute("OffsetX") && null != animationDefinition.Attribute("OffsetY")) { animation.Offset = new Vector2(int.Parse(animationDefinition.Attribute("OffsetX").Value), int.Parse(animationDefinition.Attribute("OffsetY").Value)); } animations.Add(animationAlias, animation); } }