Ah okay, I think I see the issue now! The hexagons disappear instantly, but the swap animation then starts and does its thing.
Here's what I would recommend doing. I would recommend changing the code so that it only checks and hides hexagons after a swap animation has finished playing. Depending on how the code is done, this may be easier or harder.
If tile removal is handled by a singleton or node that handles all of the individual tiles, and the individual tiles can access this node, then I'd have the tile call a function that caches both the position and number of the hexagon only when the swap animation is finished. Then you can process this list and delete the hexagons and their adjacent hexagons at that point. Something like this (pseudo code):
# In the grid
var tiles_done_swapping = []
func add_swap_tile(tile_pos, tile_id):
tiles_done_swapping.append([tile_pos, tile_id])
func _process(delta):
if (tiles_done_swapping.size() > 0):
for tile_to_swap in tiles_done_swapping:
# I don't know how your code deletes tiles, so I'll just assume
# you have a function to send a position and ID to a function
# and then it'll delete the tile at that position and all adjacent
# tiles with the same ID
delete_tiles_at_position(tile_to_swap[0]. tile_to_swap[1])
# in the individual tile
var animation
func _ready():
# get the AnimationPlayer node (assuming that's what you are using)
# and connect the animation finished signal
animation = get_node("AnimationPlayer")
animation.connect("animation_finished", self, "on_anim_finished")
func on_anim_finished(anim_name):
# assuming the swap animation is called "swap"
if (anim_name == "swap"):
# I'm assuming grid_x and grid_y is the position
# of the hexagon in the grid, and that grid_id
# is the ID displayed on the grid.
# I'm also assuming the controlling node is the parent of the tile
get_parent().add_swap_tile(Vector2(grid_x, grid_y), grid_id)
Then, theoretically, it would only delete hexagons once a hexagon has fully swapped its position. I have no idea if the code above works, but hopefully it kinda shows what I was talking about.
Another, not quite as elegant but would probably be workable solution is to add a delay with the time it takes for the hexagons to swap before you delete the hexagons. You could use a Timer node or get_tree().create_timer
and a yield statement. In either case, the duration would need to be the length of the swap animation, so everything is all synced up. Its not quite as flexible a solution, but it would work regardless of whether each tile controls itself or whether there is a node that handles all of it.
That's a couple ways I could see for handling the situation. I'm not sure if either would work, but that's what I would try doing if I was working on this issue. :smile: