diff --git a/MonoGameLibrary/Graphics/TextureAtlas.cs b/MonoGameLibrary/Graphics/TextureAtlas.cs index 65a271c..2b0bd88 100644 --- a/MonoGameLibrary/Graphics/TextureAtlas.cs +++ b/MonoGameLibrary/Graphics/TextureAtlas.cs @@ -10,7 +10,8 @@ namespace MonoGameLibrary.Graphics; public class TextureAtlas { - private TextureRegion[] _regions; + // private TextureRegion[] _regions; + private readonly Dictionary _regions; /// /// Gets or Sets the source texture represented by this texture atlas. @@ -28,9 +29,9 @@ public class TextureAtlas /// Creates a new texture atlas instance using the given texture. /// /// The source texture represented by the texture atlas. - public TextureAtlas(Texture2D texture, int spriteCount) { + public TextureAtlas(Texture2D texture) { Texture = texture; - _regions = new TextureRegion[spriteCount]; + _regions = new(); } // /// @@ -51,10 +52,9 @@ public class TextureAtlas /// /// The name of the region to retrieve. /// The TextureRegion with the specified name. - - public TextureRegion this[int id] { - get => _regions[id]; - set => _regions[id] = value; + public TextureRegion this[string name] { + get => _regions[name]; + set => _regions[name] = value; } // public TextureRegion GetRegion(string name) { @@ -96,8 +96,8 @@ public class TextureAtlas // The element contains the content path for the Texture2D to load. // So we will retrieve that value then use the content manager to load the texture. string texturePath = root.Element("Texture").Value; - int spriteCount = int.Parse(root.Attribute("count").Value); - atlas = new TextureAtlas(content.Load(texturePath), spriteCount); + // int spriteCount = int.Parse(root.Attribute("count").Value); + atlas = new TextureAtlas(content.Load(texturePath)); // The element contains individual elements, each one describing // a different texture region within the atlas. @@ -121,7 +121,7 @@ public class TextureAtlas // int width = int.Parse(region.Attribute("width")?.Value ?? "0"); // int height = int.Parse(region.Attribute("height")?.Value ?? "0"); - atlas[int.Parse(region.Attribute("id").Value)] = new TextureRegion( + atlas[region.Attribute("name").Value] = new TextureRegion( atlas.Texture, int.Parse(region.Attribute("x")?.Value ?? "0"), int.Parse(region.Attribute("y")?.Value ?? "0"),