//----------------------------------------------------------------------------- // Animation.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using Microsoft.Xna.Framework.Content; using System; using System.Diagnostics; using System.Xml; using System.Xml.Linq; namespace RolePlaying.Data { /// /// An animation description for an AnimatingSprite object. /// #if !XBOX [DebuggerDisplay("Name = {Name}")] #endif public class Animation : ContentObject { /// /// The name of the animation. /// private string name; /// /// The name of the animation. /// [ContentSerializer(Optional = true)] public string Name { get { return name; } set { name = value; } } /// /// The first frame of the animation. /// private int startingFrame; /// /// The first frame of the animation. /// public int StartingFrame { get { return startingFrame; } set { startingFrame = value; } } /// /// The last frame of the animation. /// private int endingFrame; /// /// The last frame of the animation. /// public int EndingFrame { get { return endingFrame; } set { endingFrame = value; } } /// /// The interval between frames of the animation. /// private int interval; /// /// The interval between frames of the animation. /// public int Interval { get { return interval; } set { interval = value; } } /// /// If true, the animation loops. /// private bool isLoop; /// /// If true, the animation loops. /// public bool IsLoop { get { return isLoop; } set { isLoop = value; } } /// /// Creates a new Animation object. /// public Animation() { } /// /// Creates a new Animation object by full specification. /// public Animation(string name, int startingFrame, int endingFrame, int interval, bool isLoop) { this.Name = name; this.StartingFrame = startingFrame; this.EndingFrame = endingFrame; this.Interval = interval; this.IsLoop = isLoop; } /// /// Read an Animation object from the content pipeline. /// public class AnimationReader : ContentTypeReader { /// /// Read an Animation object from the content pipeline. /// protected override Animation Read(ContentReader input, Animation existingInstance) { Animation animation = existingInstance; if (animation == null) { animation = new Animation(); } animation.AssetName = input.AssetName; animation.Name = input.ReadString(); animation.StartingFrame = input.ReadInt32(); animation.EndingFrame = input.ReadInt32(); animation.Interval = input.ReadInt32(); animation.IsLoop = input.ReadBoolean(); return animation; } } internal static Animation Load(XElement animationElement, ContentManager contentManager) { var animation = new Animation { AssetName = animationElement?.Value, Name = animationElement?.Element("Name")?.Value, StartingFrame = (int?)animationElement?.Element("StartingFrame") ?? 0, EndingFrame = (int?)animationElement?.Element("EndingFrame") ?? 0, Interval = (int?)animationElement?.Element("Interval") ?? 100, IsLoop = (bool?)animationElement?.Element("IsLoop") ?? false, }; return animation; } } }