Skip to content

Commit

Permalink
Change draw process
Browse files Browse the repository at this point in the history
Draw tile on center of cell, then add tile shift (get custom property "originaX" and "originalY")
  • Loading branch information
ElonDev committed Jan 25, 2015
1 parent 5794500 commit 5a97ea6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libtiled/maprenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,17 @@ void CellRenderer::render(const Cell &cell, const QPointF &pos, Origin origin)
const QPoint offset = cell.tile->tileset()->tileOffset();
const QPointF sizeHalf = QPointF(size.width() / 2, size.height() / 2);

// Cell size is fixed to 86x43, get half size to set position correctly.
float cellHalfWidth = 43;
float cellHalfHeight = 21.5;

QPointF originalOffset;
originalOffset.setX(cell.tile->property(QLatin1String("originalX")).toFloat(0));
originalOffset.setY(cell.tile->property(QLatin1String("originalY")).toFloat(0));

QPainter::PixmapFragment fragment;
fragment.x = pos.x() + offset.x() + sizeHalf.x();
fragment.y = pos.y() + offset.y() + sizeHalf.y() - size.height();
fragment.x = pos.x() + offset.x() + sizeHalf.x() + cellHalfWidth - originalOffset.x();
fragment.y = pos.y() + offset.y() + sizeHalf.y() - cellHalfHeight - originalOffset.y();
fragment.sourceLeft = 0;
fragment.sourceTop = 0;
fragment.width = size.width();
Expand Down

0 comments on commit 5a97ea6

Please sign in to comment.