diff --git a/src/Tools/Move.gd b/src/Tools/Move.gd index 0874430f7..7b538f630 100644 --- a/src/Tools/Move.gd +++ b/src/Tools/Move.gd @@ -21,6 +21,13 @@ func _input(event: InputEvent) -> void: if Global.current_project.has_selection: var prev_pos = selection_node.big_bounding_rectangle.position selection_node.big_bounding_rectangle.position = prev_pos.snapped(grid_size) + # The First time transform_snap_grid is enabled then _snap_position() is not called + # and selection had wrong offset so i chose to do selection offsetting here + var grid_offset = Vector2(Global.grid_offset_x, Global.grid_offset_y) + grid_offset = Vector2( + fmod(grid_offset.x, grid_size.x), fmod(grid_offset.y, grid_size.y) + ) + selection_node.big_bounding_rectangle.position += grid_offset selection_node.marching_ants_outline.offset += ( selection_node.big_bounding_rectangle.position - prev_pos @@ -97,9 +104,19 @@ func _snap_position(position: Vector2) -> Vector2: if _snap_to_grid: # Snap to grid var grid_size := Vector2(Global.grid_width, Global.grid_height) position = position.snapped(grid_size) - var grid_offset = Vector2(Global.grid_offset_x, Global.grid_offset_y) - grid_offset = Vector2(fmod(grid_offset.x, grid_size.x), fmod(grid_offset.y, grid_size.y)) - position += grid_offset + # The part below only corrects the offset for situations when there is no selection + # Offsets when there is selection is controlled in _input() function + if !Global.current_project.has_selection: + var move_offset := Vector2.ZERO + move_offset.x = ( + _start_pos.x + - int(_start_pos.x / Global.grid_width) * Global.grid_width + ) + move_offset.y = ( + _start_pos.y + - int(_start_pos.y / Global.grid_height) * Global.grid_height + ) + position += move_offset return position