Prechádzať zdrojové kódy

Fix rotated/flipped tiles rendering origin

Gilles Roudière 4 mesiacov pred
rodič
commit
52aee9c325

+ 7 - 2
editor/plugins/tiles/tile_map_layer_editor.cpp

@@ -988,19 +988,24 @@ void TileMapLayerEditorTilesPlugin::forward_canvas_draw_over_viewport(Control *p
 
 							bool transpose = tile_data->get_transpose() ^ bool(E.value.alternative_tile & TileSetAtlasSource::TRANSFORM_TRANSPOSE);
 							if (transpose) {
-								dest_rect.position = (tile_set->map_to_local(E.key) - Vector2(dest_rect.size.y, dest_rect.size.x) / 2 - tile_offset);
+								dest_rect.position = (tile_set->map_to_local(E.key) - Vector2(dest_rect.size.y, dest_rect.size.x) / 2);
+								SWAP(tile_offset.x, tile_offset.y);
 							} else {
-								dest_rect.position = (tile_set->map_to_local(E.key) - dest_rect.size / 2 - tile_offset);
+								dest_rect.position = (tile_set->map_to_local(E.key) - dest_rect.size / 2);
 							}
 
 							if (tile_data->get_flip_h() ^ bool(E.value.alternative_tile & TileSetAtlasSource::TRANSFORM_FLIP_H)) {
 								dest_rect.size.x = -dest_rect.size.x;
+								tile_offset.x = -tile_offset.x;
 							}
 
 							if (tile_data->get_flip_v() ^ bool(E.value.alternative_tile & TileSetAtlasSource::TRANSFORM_FLIP_V)) {
 								dest_rect.size.y = -dest_rect.size.y;
+								tile_offset.y = -tile_offset.y;
 							}
 
+							dest_rect.position -= tile_offset;
+
 							// Get the tile modulation.
 							Color modulate = tile_data->get_modulate() * edited_layer->get_modulate_in_tree() * edited_layer->get_self_modulate();
 

+ 7 - 2
scene/2d/tile_map_layer.cpp

@@ -2609,19 +2609,24 @@ void TileMapLayer::draw_tile(RID p_canvas_item, const Vector2 &p_position, const
 
 		bool transpose = tile_data->get_transpose() ^ bool(p_alternative_tile & TileSetAtlasSource::TRANSFORM_TRANSPOSE);
 		if (transpose) {
-			dest_rect.position = (p_position - Vector2(dest_rect.size.y, dest_rect.size.x) / 2 - tile_offset);
+			dest_rect.position = (p_position - Vector2(dest_rect.size.y, dest_rect.size.x) / 2);
+			SWAP(tile_offset.x, tile_offset.y);
 		} else {
-			dest_rect.position = (p_position - dest_rect.size / 2 - tile_offset);
+			dest_rect.position = (p_position - dest_rect.size / 2);
 		}
 
 		if (tile_data->get_flip_h() ^ bool(p_alternative_tile & TileSetAtlasSource::TRANSFORM_FLIP_H)) {
 			dest_rect.size.x = -dest_rect.size.x;
+			tile_offset.x = -tile_offset.x;
 		}
 
 		if (tile_data->get_flip_v() ^ bool(p_alternative_tile & TileSetAtlasSource::TRANSFORM_FLIP_V)) {
 			dest_rect.size.y = -dest_rect.size.y;
+			tile_offset.y = -tile_offset.y;
 		}
 
+		dest_rect.position -= tile_offset;
+
 		// Draw the tile.
 		if (p_frame >= 0) {
 			Rect2i source_rect = atlas_source->get_runtime_tile_texture_region(p_atlas_coords, p_frame);