diff --git a/map.cpp b/map.cpp index f72d758d..5752ac62 100755 --- a/map.cpp +++ b/map.cpp @@ -157,22 +157,26 @@ QImage Map::getMetatileImage(int tile) { for (int x = 0; x < 2; x++) { Tile tile_ = metatile->tiles->value((y * 2) + x + (layer * 4)); QImage tile_image = getMetatileTile(tile_.tile); - //if (tile_image.isNull()) { - // continue; - //} - //if (blockTileset->palettes) { - QList palette = palettes.value(tile_.palette); - for (int j = 0; j < palette.length(); j++) { - tile_image.setColor(j, palette.value(j)); - } - //} - //QVector vector = palette.toVector(); - //tile_image.setColorTable(vector); + if (tile_image.isNull()) { + // Some metatiles specify tiles that are outside the valid range. + // These are treated as completely transparent, so they can be skipped without + // being drawn. + continue; + } + + // Colorize the metatile tiles with its palette. + QList palette = palettes.value(tile_.palette); + for (int j = 0; j < palette.length(); j++) { + tile_image.setColor(j, palette.value(j)); + } + + // The top layer of the metatile has its last color displayed at transparent. if (layer > 0) { QColor color(tile_image.color(15)); color.setAlpha(0); tile_image.setColor(15, color.rgba()); } + QPoint origin = QPoint(x*8, y*8); metatile_painter.drawImage(origin, tile_image.mirrored(tile_.xflip == 1, tile_.yflip == 1)); }