public TextureAtlas(AtlasData data) { if (data != null) { load(data); } }
private void load(AtlasData data) { Dictionary <Page, Texture2D> pageToTexture = new Dictionary <Page, Texture2D>(); foreach (Page page in data.pages) { Texture2D texture = null; if (page.texture == null) { // TODO: implemetn minmaps and format and wrapping // texture = new Texture2D(ArchonGame.graphics.GraphicsDevice,(int)page.width,(int)page.height,false,page.format); texture = page.textureFile.asTexture(); } else { texture = page.texture; } textures.Add(texture); pageToTexture.Add(page, texture); } foreach (Region region in data.regions) { int width = region.width; int height = region.height; AtlasRegion atlasRegion = new AtlasRegion(pageToTexture[region.page], region.left, region.top, region.rotate ? height : width, region.rotate ? width: height); atlasRegion.index = region.index; atlasRegion.name = region.name; atlasRegion.xOff = region.xOff; atlasRegion.yOff = region.yOff; atlasRegion.originalWidth = region.originalWidth; atlasRegion.originalHeight = region.originalHeight; atlasRegion.rotate = region.rotate; atlasRegion.splits = region.splits; atlasRegion.pads = region.pads; if (region.flip) { atlasRegion.flip(false, true); } regions.Add(atlasRegion); } }