private void GenerateTileSourceRectangles() { // process the tilesets, calculate tiles to fit in each set, calculate source rectangles foreach (TileSetContent tileSet in tileSets) { int imageWidth = tileSet.Texture.Width; int imageHeight = tileSet.Texture.Height; imageWidth -= tileSet.Margin * 2; imageHeight -= tileSet.Margin * 2; int tileCountX = 0; while ((tileCountX + 1) * tileSet.TileWidth <= imageWidth) { tileCountX++; imageWidth -= tileSet.Spacing; } int tileCountY = 0; while ((tileCountY + 1) * tileSet.TileHeight <= imageHeight) { tileCountY++; imageHeight -= tileSet.Spacing; } for (int y = 0; y < tileCountY; y++) { for (int x = 0; x < tileCountX; x++) { int rx = tileSet.Margin + x * (tileSet.TileWidth + tileSet.Spacing); int ry = tileSet.Margin + y * (tileSet.TileHeight + tileSet.Spacing); Rectangle source = new Rectangle(rx, ry, tileSet.TileWidth, tileSet.TileHeight); int index = tileSet.FirstGID + (y * tileCountX + x); PropertyCollection tileProperties = new PropertyCollection(); if (tileSet.TileProperties.ContainsKey(index)) { tileProperties = tileSet.TileProperties[index]; } TileContent tile = new TileContent(source, tileProperties); tileSet.Tiles.Add(tile); } } } }
private void GenerateTileSourceRectangles() { // process the tilesets, calculate tiles to fit in each set, calculate source rectangles foreach (TileSetContent tileSet in tileSets) { int imageWidth = tileSet.Texture.Width; int imageHeight = tileSet.Texture.Height; imageWidth -= tileSet.Margin * 2; imageHeight -= tileSet.Margin * 2; int tileCountX = 0; while ((tileCountX + 1) * tileSet.TileWidth <= imageWidth) { tileCountX++; imageWidth -= tileSet.Spacing; } int tileCountY = 0; while ((tileCountY + 1) * tileSet.TileHeight <= imageHeight) { tileCountY++; imageHeight -= tileSet.Spacing; } for (int y = 0; y < tileCountY; y++) { for (int x = 0; x < tileCountX; x++) { int rx = tileSet.Margin + x * (tileSet.TileWidth + tileSet.Spacing); int ry = tileSet.Margin + y * (tileSet.TileHeight + tileSet.Spacing); Rectangle source = new Rectangle(rx, ry, tileSet.TileWidth, tileSet.TileHeight); int index = tileSet.FirstGID + (y * tileCountX + x); PropertyCollection tileProperties = new PropertyCollection(); if (tileSet.TileProperties.ContainsKey(index)) tileProperties = tileSet.TileProperties[index]; TileContent tile = new TileContent(source, tileProperties); tileSet.Tiles.Add(tile); } } } }