Esempio n. 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);
        }
Esempio n. 2
0
        public static Dictionary <string, SpriteAnimationFrameSpriteSheet> FromDefinitionFile(SpriteSheetDefinition definition, ContentManager content)
        {
            var spriteSheet = content.Load <Texture2D>(definition.AssetName);
            var result      = new Dictionary <string, SpriteAnimationFrameSpriteSheet>();

            foreach (var imageDefinition in definition.ImageDefinitions)
            {
                result.Add(imageDefinition.Key, new SpriteAnimationFrameSpriteSheet(spriteSheet, imageDefinition.Value));
            }

            return(result);
        }
Esempio n. 3
0
        public static Dictionary <string, SpriteAnimationFrameSpriteSheet> FromDefinitionFile(string definitionLocation, ContentManager content)
        {
            var definition = SpriteSheetDefinition.LoadFromFile(definitionLocation);

            return(FromDefinitionFile(definition, content));
        }