Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sprite.X = getIntAttribute(reader, "x");
- <Texture image="astro.png" width="221" height="611">
- <region n="astro_E.png" x="0" y="0" w="56" h="163"/>
- <region n="astro_ENE.png" x="180" y="0" w="41" h="151"/>
- <region n="astro_ESE.png" x="177" y="151" w="41" h="151"/>
- <region n="astro_N.png" x="56" y="0" w="62" h="149"/>
- ...
- </Texture >
- public class Texture
- {
- public int Width { get; set; }
- public int Height { get; set; }
- public string ImagePath { get; set; }
- public List<Texture> SpriteList { get; set; } = new List<Texture>();
- }
- public class Region
- {
- public int Height { get; set; }
- public int Width { get; set; }
- public int X { get; set; }
- public int Y { get; set; }
- public string Name { get; set; }
- public bool Rotate { get; set; }
- }
- public void read(string filename)
- {
- Texture textureAtlas = new Texture();
- using (var reader = XmlReader.Create(filename))
- {
- reader.MoveToContent();
- textureAtlas.Height = getIntAttribute(reader, "height");
- textureAtlas.Width = getIntAttribute(reader, "width");
- textureAtlas.ImagePath = getAttribute(reader, "imagePath");
- while (reader.Read())
- {
- Region sprite = new Region();
- reader.MoveToContent();
- sprite.Name = getAttribute(reader, "n");
- sprite.X = getIntAttribute(reader, "x"); //ArgumentNullException here
- sprite.Y = getIntAttribute(reader, "y");
- sprite.Width = getIntAttribute(reader, "w");
- sprite.Height = getIntAttribute(reader, "h");
- sprite.Rotate = getBoolAttribute(reader, "r");
- textureAtlas.SpriteList.Add(sprite);
- }
- }
- }
- private string getAttribute(XmlReader reader, string attributeName)
- {
- return reader.GetAttribute(attributeName);
- }
- private int getIntAttribute(XmlReader reader, string attributeName)
- {
- return int.Parse(reader.GetAttribute(attributeName));
- }
Add Comment
Please, Sign In to add comment