public byte [] Render(TileSet activeTileSet) { TileSheet cre = activeTileSet.MyCreSheet; TileSheet sce = activeTileSet.MySceSheet; Palette p = activeTileSet.MyPalette; int firstCreTileIndex = 0x280; byte [] image = new byte [256 * 256 * 4]; for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { GetData(x, y, out int tile, out int row, out bool hFlip, out bool vFlip); // int tile = GetTile (x, y); if (tile < firstCreTileIndex) { sce.DrawTile(image, 256, 256, p, row, 8 * x, 8 * y, tile, hFlip, vFlip); } else { cre.DrawTile(image, 256, 256, p, row, 8 * x, 8 * y, tile - firstCreTileIndex, hFlip, vFlip); } } } return(image); }
//---------------------------------------------------------------------------------------- // Render a 16x16 tile from the tile map to a byte array (BGRA). public byte [] RenderTile(int index) { if (index < 0 || index > RowCount * ColCount) { return(null); } int row = index / ColCount; int col = index % ColCount; int FirstSceTileRow = 8; // [wip] make static field? int firstCreTileIndex = 0x280; int width = 16; // Tile is 16 pixels wide int height = 16; // and 16 pixels high. TileTable table = MyCreTable; if (row >= FirstSceTileRow) { table = MySceTable; row -= FirstSceTileRow; } byte [] image = new byte [width * height * 4]; for (int q1 = 0; q1 < 2; q1++) { for (int q0 = 0; q0 < 2; q0++) { int quadrant = 2 * q1 + q0; int tile8Index = table.GetTile8Index(ColCount * row + col, quadrant); int paletteRow = table.GetPaletteRow(ColCount * row + col, quadrant); bool hFlip = table.GetHFlip(ColCount * row + col, quadrant); bool vFlip = table.GetVFlip(ColCount * row + col, quadrant); if (tile8Index < firstCreTileIndex) { MySceSheet.DrawTile(image, width, height, MyPalette, paletteRow, 8 * q0, 8 * q1, tile8Index, hFlip, vFlip); } else { MyCreSheet.DrawTile(image, width, height, MyPalette, paletteRow, 8 * q0, 8 * q1, tile8Index - firstCreTileIndex, hFlip, vFlip); } } } return(image); }
// Loads full tilesheet into an image. public BlitImage TilesheetToImage(int tilesheetIndex, int paletteIndex) { TileSheet t = (TileSheet)TileSheets [tilesheetIndex]; CompressedPalette p = (CompressedPalette)Palettes [paletteIndex]; byte [] data = new byte [16 * 64 * 64 * 4]; for (int row = 0; row < 64; row++) { for (int col = 0; col < 16; col++) { t.DrawTile(data, 16 * 8, 64 * 8, p, 0, 8 * col, 8 * row, 16 * row + col, false, false); } } return(new BlitImage(data, 16 * 8)); }