diff options
| author | Poommetee Ketson <poommetee@protonmail.com> | 2017-12-01 11:46:34 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-01 11:46:34 +0700 |
| commit | e89309b9315d45eb4719180ea75f1db9fc2190a1 (patch) | |
| tree | b4da26bbf7233dd37ae94877ab25b7e3ab5449c7 /scene/2d/tile_map.cpp | |
| parent | 66f60a848e54b11a57f00cb50bda7cd549ab549c (diff) | |
| parent | 2beadf7ac0d9a0dbe1df1d96c1f0d36bbcfadbcc (diff) | |
| download | redot-engine-e89309b9315d45eb4719180ea75f1db9fc2190a1.tar.gz | |
Merge pull request #13216 from hoelzl/pr-fix-tile-origin-center
Fix displacement for centered tilemaps
Diffstat (limited to 'scene/2d/tile_map.cpp')
| -rw-r--r-- | scene/2d/tile_map.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 2329ce8644..c7b656b5fc 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -215,6 +215,9 @@ void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) offset.y += cell_size.y; + else if (tile_origin == TILE_ORIGIN_CENTER) { + offset += cell_size / 2; + } if (s.y > s.x) { if ((p_cell.flip_h && (p_cell.flip_v || p_cell.transpose)) || (p_cell.flip_v && !p_cell.transpose)) @@ -235,6 +238,8 @@ void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const xform.elements[1].x = -xform.elements[1].x; if (tile_origin == TILE_ORIGIN_TOP_LEFT || tile_origin == TILE_ORIGIN_BOTTOM_LEFT) offset.x = s.x - offset.x; + else if (tile_origin == TILE_ORIGIN_CENTER) + offset.x = s.x - offset.x / 2; } if (p_cell.flip_v) { xform.elements[0].y = -xform.elements[0].y; @@ -242,10 +247,9 @@ void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const if (tile_origin == TILE_ORIGIN_TOP_LEFT) offset.y = s.y - offset.y; else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) { - if (p_cell.transpose) - offset.y += s.y; - else - offset.y -= s.y; + offset.y += s.y; + } else if (tile_origin == TILE_ORIGIN_CENTER) { + offset.y += s.y; } } xform.elements[2].x += offset.x; @@ -429,20 +433,18 @@ void TileMap::_update_dirty_quadrants() { } } else if (tile_origin == TILE_ORIGIN_CENTER) { - rect.position += tcenter; - Vector2 center = (s / 2) - tile_ofs; - center_ofs = tcenter - (s / 2); + rect.position += tile_ofs; if (c.flip_h) - rect.position.x -= s.x - center.x; + rect.position.x -= cell_size.x / 2; else - rect.position.x -= center.x; + rect.position.x += cell_size.x / 2; if (c.flip_v) - rect.position.y -= s.y - center.y; + rect.position.y -= cell_size.y / 2; else - rect.position.y -= center.y; + rect.position.y += cell_size.y / 2; } Ref<Texture> normal_map = tile_set->tile_get_normal_map(c.id); |
