Thanks a lot.
I have some questions though.
export var puzzle_dimensions:Vector2 = Vector2(3,4)
is the grid's number of cells(4 columns, 5 rows)? So in my case will be Vector2(3,5), because the image is divided to 24 pieces(4 columns and 6 rows), if the count starts from 0.
And also the tilemap's position doesn't start at position 0,0 but is a bit right and down.
I already tried to calculate it(I have updated my first post) like this:
first_touch = get_global_mouse_position()
var first_with_offset = first_touch - $Background/Grid.position
first_cell = $Background/Grid.world_to_map(first_with_offset)
final_touch = get_global_mouse_position()
var final_with_offset = first_touch - $Background/Grid.position
first_cell = $Background/Grid.world_to_map(final_with_offset)
I started to implement your suggestions, but seems that doesn't work for me.
With the function I had in "ready", I had the picture drawn on screen, but with the "solvedpuzzle" function I just get the first tile of every image I had in tileset. At this time I have 2 images on the tileset. I set them like this:
- Drag and drop the first image in tileset editor
- Select it and press the +New Atlas button
- Set the cell to 130x158
- In region tap I select all image to get the divided 24 cells for the image
Same procedure for the 2nd image.
-Save the tileset.
I din't find a way to draw all image's tiles, I returned to my function to display the solved image, and I managed to make it work.
I created 2 more variables to store the autotile's coordinations and with this I can swap the tiles. I put all those in 2 new fucntions which I use in "touch" and "release" input if statements:
var first_with_offset = first_touch - puzzle.position
first_cell = puzzle.world_to_map(first_with_offset)
if is_in_grid(first_cell.x, first_cell.y):
grid_controling = true
cell_one = puzzle.get_cell(first_cell.x, first_cell.y)
autotile_one = puzzle.get_cell_autotile_coord(first_cell.x, first_cell.y)
#print("cell1 " + str(autotile_one))
var final_with_offset = final_touch - puzzle.position
sec_cell = puzzle.world_to_map(final_with_offset)
if is_in_grid(sec_cell.x,sec_cell.y) and grid_controling:
cell_two = puzzle.get_cell(sec_cell.x, sec_cell.y)
autotile_two = puzzle.get_cell_autotile_coord(sec_cell.x, sec_cell.y)
#print("cell2 " + str(puzzle.get_cell_autotile_coord(sec_cell.x,sec_cell.y)))
puzzle.set_cell(sec_cell.x, sec_cell.y , cell_one, false, false, false, Vector2(autotile_one))
puzzle.set_cell(first_cell.x, first_cell.y, cell_two, false, false, false, Vector2(autotile_two))
Like this works, but there are 2 more problems now:
1. Limit the draw and swap tile actions in the area of those 24 cells
2. Limit swipe to only the next tile up/down/left/right from the first.