Example #1
0
        public static SpriteSheetDefinition LoadFromFile(string location)
        {
            var xDoc = new XmlDocument();

            xDoc.Load(Path.Combine("Content", location));

            var rootNode = xDoc.GetElementsByTagName("TextureAtlas")[0];

            var asset  = rootNode.Attributes["imagePath"].Value;
            var result = new SpriteSheetDefinition();

            result.AssetName = Path.Combine(Path.GetDirectoryName(location), asset);

            var spriteNodes = xDoc.GetElementsByTagName("sprite");

            foreach (XmlNode n in spriteNodes)
            {
                var imageDefinition = new SpriteSheetImageDefinition
                {
                    Name = n.Attributes["n"].Value,

                    SrcRectangle = new Rectangle(
                        Convert.ToInt32(n.Attributes["x"].Value),
                        Convert.ToInt32(n.Attributes["y"].Value),
                        Convert.ToInt32(n.Attributes["w"].Value),
                        Convert.ToInt32(n.Attributes["h"].Value)),

                    Origin = new Vector2(
                        Convert.ToSingle(n.Attributes["pX"].Value, new CultureInfo("en-US")) * Convert.ToInt32(n.Attributes["w"].Value),
                        Convert.ToSingle(n.Attributes["pY"].Value, new CultureInfo("en-US")) * Convert.ToInt32(n.Attributes["h"].Value)),
                };

                if (n.Attributes["oX"] != null)
                {
                    imageDefinition.FrameOffset = new Vector2(Convert.ToSingle(n.Attributes["oX"].Value), Convert.ToSingle(n.Attributes["oY"].Value));
                }
                else
                {
                    imageDefinition.FrameOffset = Vector2.Zero;
                }

                result.ImageDefinitions.Add(imageDefinition.Name, imageDefinition);
            }
            return(result);
        }
Example #2
0
 public SpriteAnimationFrameSpriteSheet(Texture2D spriteSheet, SpriteSheetImageDefinition definition)
 {
     this.spriteSheet = spriteSheet;
     this.definition  = definition;
 }