Пример #1
0
        public TextureAtlas Parse(string dataFilePath)
        {
            if (!File.Exists(dataFilePath))
            {
                throw new FileNotFoundException(nameof(dataFilePath) + $" : {dataFilePath}");
            }
            var xml = XDocument.Load(dataFilePath);
            var atlasDetails = new {
                Width = (int)xml.Element("TextureAtlas").Attribute("width"),
                Height = (int)xml.Element("TextureAtlas").Attribute("height"),
                TextureRegions = from s in xml.Root.Descendants("sprite")
                    select new {
                        X = (int)s.Attribute("x"),
                        Y = (int)s.Attribute("y"),
                        Width = (int)s.Attribute("w"),
                        Height = (int)s.Attribute("h")
                    }
            };

            var textureAtlas = new TextureAtlas(atlasDetails.Width, atlasDetails.Height);
            foreach (var region in atlasDetails.TextureRegions)
            {
                textureAtlas.Add(new TextureRegion(region.X, region.Y, region.Width, region.Height));
            }
            return textureAtlas;
        }
Пример #2
0
 internal SpriteSheet(ITexture texture, string dataFilePath, TexturePackerParser parser)
 {
     ValidateArguments(texture, dataFilePath, parser);
     this.Texture = texture;
     this.textureAtlas = parser.Parse(dataFilePath);
 }
Пример #3
0
 public void SetUp()
 {
     atlas = new TextureAtlas(200, 400);
 }