public FixedSizeSpritePacker(int width, int height, int padding) { if (width <= 1) { throw new SpriteException($"Invalid packer width: {width}"); } if (height <= 1) { throw new SpriteException($"Invalid packer height: {width}"); } if (padding < 0) { padding = 0; } Padding = padding; Width = width; Height = height; RootRegion = new PackerRegion(new Rectangle(0, 0, width, height)); texture = SpriteAtlas.CreateTexture(width, height); }
// TODO create a 'shrink' option that discards unused margins to minimize texture size. public SpriteAtlas CreateSpriteAtlas(bool disposeTextures) { SpriteAtlas a = new SpriteAtlas(Width, Height); a.SetTexture(texture); foreach (var item in prePacked) { a.Blit(item.Texture, item.PackedPosition, Padding); a.AddSprite(item.FutureSprite); } if (disposeTextures) { foreach (var item in prePacked) { item.Texture?.Dispose(); item.Texture = null; } } a.Finish(); return(a); }