diff --git a/src/libtiled/map.cpp b/src/libtiled/map.cpp index f683f322fa..11a2d1544f 100644 --- a/src/libtiled/map.cpp +++ b/src/libtiled/map.cpp @@ -416,15 +416,20 @@ void Map::normalizeTileLayerPositionsAndMapSize() while (auto tileLayer = static_cast(it.next())) contentRect |= tileLayer->region().boundingRect(); - if (!contentRect.isEmpty()) { - QPoint offset = contentRect.topLeft(); + if (!contentRect.topLeft().isNull()) { it.toFront(); while (auto tileLayer = static_cast(it.next())) - tileLayer->setPosition(tileLayer->position() - offset); + tileLayer->setPosition(tileLayer->position() - contentRect.topLeft()); - setWidth(contentRect.width()); - setHeight(contentRect.height()); + // Adjust the stagger index when layers are moved by odd amounts + const int staggerOffSet = (staggerAxis() == Map::StaggerX ? contentRect.x() + : contentRect.y()) % 2; + + setStaggerIndex(static_cast((staggerIndex() + staggerOffSet) % 2)); } + + setWidth(contentRect.width()); + setHeight(contentRect.height()); } /** diff --git a/src/tiled/capturestamphelper.cpp b/src/tiled/capturestamphelper.cpp index d9be5a7a42..e50aaae0a1 100644 --- a/src/tiled/capturestamphelper.cpp +++ b/src/tiled/capturestamphelper.cpp @@ -72,16 +72,12 @@ TileStamp CaptureStampHelper::endCapture(const MapDocument &mapDocument, QPoint } if (stamp->layerCount() > 0) { - auto staggerIndex = stamp->staggerIndex(); + // Adjust the stagger index when the capture starts at an odd offset + const auto staggerIndex = stamp->staggerIndex(); + const int staggerOffSet = (stamp->staggerAxis() == Map::StaggerX ? captured.x() + : captured.y()) % 2; - // Gets if the relative stagger should be the same as the base layer - int staggerIndexOffSet; - if (stamp->staggerAxis() == Map::StaggerX) - staggerIndexOffSet = captured.x() % 2; - else - staggerIndexOffSet = captured.y() % 2; - - stamp->setStaggerIndex(static_cast((staggerIndex + staggerIndexOffSet) % 2)); + stamp->setStaggerIndex(static_cast((staggerIndex + staggerOffSet) % 2)); // Add tileset references to map stamp->addTilesets(stamp->usedTilesets());