daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sprite.X = getIntAttribute(reader, "x");
  2.    
  3. <Texture image="astro.png" width="221" height="611">
  4.     <region n="astro_E.png" x="0" y="0" w="56" h="163"/>
  5.     <region n="astro_ENE.png" x="180" y="0" w="41" h="151"/>
  6.     <region n="astro_ESE.png" x="177" y="151" w="41" h="151"/>
  7.     <region n="astro_N.png" x="56" y="0" w="62" h="149"/>
  8.     ...
  9. </Texture >
  10.    
  11. public class Texture
  12. {
  13.     public int Width    { get; set; }
  14.     public int Height   { get; set; }
  15.     public string ImagePath { get; set; }
  16.     public List<Texture> SpriteList { get; set; } = new List<Texture>();
  17. }
  18.  
  19. public class Region
  20. {
  21.     public int Height   { get; set; }
  22.     public int Width    { get; set; }
  23.     public int X { get; set; }
  24.     public int Y { get; set; }
  25.     public string Name { get; set; }
  26.     public bool Rotate { get; set; }
  27. }
  28.    
  29. public void read(string filename)
  30. {
  31.  
  32.     Texture textureAtlas = new Texture();
  33.  
  34.     using (var reader = XmlReader.Create(filename))
  35.     {
  36.         reader.MoveToContent();
  37.         textureAtlas.Height = getIntAttribute(reader, "height");
  38.         textureAtlas.Width = getIntAttribute(reader, "width");
  39.         textureAtlas.ImagePath = getAttribute(reader, "imagePath");
  40.  
  41.         while (reader.Read())
  42.         {
  43.             Region sprite = new Region();
  44.  
  45.             reader.MoveToContent();
  46.  
  47.             sprite.Name = getAttribute(reader, "n");
  48.             sprite.X = getIntAttribute(reader, "x"); //ArgumentNullException here
  49.             sprite.Y = getIntAttribute(reader, "y");
  50.             sprite.Width = getIntAttribute(reader, "w");
  51.             sprite.Height = getIntAttribute(reader, "h");
  52.             sprite.Rotate = getBoolAttribute(reader, "r");
  53.  
  54.             textureAtlas.SpriteList.Add(sprite);
  55.         }
  56.     }
  57. }
  58.  
  59. private string getAttribute(XmlReader reader, string attributeName)
  60. {
  61.     return reader.GetAttribute(attributeName);
  62. }
  63.  
  64. private int getIntAttribute(XmlReader reader, string attributeName)
  65. {
  66.     return int.Parse(reader.GetAttribute(attributeName));
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top