From e22e0cecf7bdf7f16956e4657df4b6de77bdee24 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Sat, 2 Jan 2016 18:17:20 +0100 Subject: [PATCH] TileMap: Consider texture offset for rotated tiles --- scene/2d/tile_map.cpp | 11 +++++++++-- .../editor/plugins/tile_map_editor_plugin.cpp | 18 +++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index 7ae87b881c6..70937c68dac 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -379,10 +379,17 @@ void TileMap::_update_dirty_quadrants() { /* rect.size.x+=fp_adjust; rect.size.y+=fp_adjust;*/ - if (c.flip_h) + if (c.transpose) + SWAP(tile_ofs.x, tile_ofs.y); + + if (c.flip_h) { rect.size.x=-rect.size.x; - if (c.flip_v) + tile_ofs.x=-tile_ofs.x; + } + if (c.flip_v) { rect.size.y=-rect.size.y; + tile_ofs.y=-tile_ofs.y; + } Vector2 center_ofs; diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp index b2562eafe1a..5ee0259d56a 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.cpp +++ b/tools/editor/plugins/tile_map_editor_plugin.cpp @@ -676,12 +676,21 @@ void TileMapEditor::_canvas_draw() { Ref t = ts->tile_get_texture(st); if (t.is_valid()) { Vector2 from = node->map_to_world(over_tile)+node->get_cell_draw_offset(); + Vector2 tile_ofs = ts->tile_get_texture_offset(st); Rect2 r = ts->tile_get_region(st); Size2 sc = xform.get_scale(); - if (mirror_x->is_pressed()) + + if (transpose->is_pressed()) + SWAP(tile_ofs.x, tile_ofs.y); + + if (mirror_x->is_pressed()) { sc.x*=-1.0; - if (mirror_y->is_pressed()) + tile_ofs.x*=-1.0; + } + if (mirror_y->is_pressed()) { sc.y*=-1.0; + tile_ofs.y*=-1.0; + } Rect2 rect; if (r==Rect2()) { @@ -691,15 +700,14 @@ void TileMapEditor::_canvas_draw() { rect=Rect2(from,r.get_size()); } - if (node->get_tile_origin()==TileMap::TILE_ORIGIN_TOP_LEFT) { - rect.pos+=ts->tile_get_texture_offset(st); + rect.pos+=tile_ofs; } else if (node->get_tile_origin()==TileMap::TILE_ORIGIN_CENTER) { rect.pos+=node->get_cell_size()/2; Vector2 s = r.size; - Vector2 center = (s/2) - ts->tile_get_texture_offset(st); + Vector2 center = (s/2) - tile_ofs; if (mirror_x->is_pressed())