diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-09-26 10:56:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-26 10:56:26 +0200 |
commit | fba8ee470266db349de9421dbe5f5b575b91077b (patch) | |
tree | 63058494e5969a1b1a897df29153aa4df5ce3aad | |
parent | 452741f33329e1827c31b0eb69f15e7bf8cc35fa (diff) | |
parent | 943471dd02a94dee108e3586239d72b5baa13174 (diff) |
Merge pull request #31949 from myhalibobo/TilemapFix
Fix tilemap world_to_map return error map coordinates
-rw-r--r-- | scene/2d/tile_map.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index c0c1d8f691..2bfdfd7d02 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -1549,7 +1549,8 @@ Vector2 TileMap::_map_to_world(int p_x, int p_y, bool p_ignore_ofs) const { ret += get_cell_transform()[1] * (half_offset == HALF_OFFSET_Y ? 0.5 : -0.5); } } break; - default: { + case HALF_OFFSET_DISABLED: { + // Nothing to do. } } } @@ -1612,26 +1613,27 @@ Vector2 TileMap::world_to_map(const Vector2 &p_pos) const { switch (half_offset) { case HALF_OFFSET_X: { - if (ret.y > 0 ? int(ret.y) & 1 : (int(ret.y) - 1) & 1) { + if (int(floor(ret.y)) & 1) { ret.x -= 0.5; } } break; case HALF_OFFSET_NEGATIVE_X: { - if (ret.y > 0 ? int(ret.y) & 1 : (int(ret.y) - 1) & 1) { + if (int(floor(ret.y)) & 1) { ret.x += 0.5; } } break; case HALF_OFFSET_Y: { - if (ret.x > 0 ? int(ret.x) & 1 : (int(ret.x) - 1) & 1) { + if (int(floor(ret.x)) & 1) { ret.y -= 0.5; } } break; case HALF_OFFSET_NEGATIVE_Y: { - if (ret.x > 0 ? int(ret.x) & 1 : (int(ret.x) - 1) & 1) { + if (int(floor(ret.x)) & 1) { ret.y += 0.5; } } break; - default: { + case HALF_OFFSET_DISABLED: { + // Nothing to do. } } |