Godot Version
4.3 beta 1
Question
I’m using a TileMapLayer with scenes to act as a board for a card game, for various reasons.
I’ve managed to implement a drag and drop of cards on the tilemap, which works visually. Cards are snapped to relevant grid positions without issue.
However, I’m wanting to make use of the tilemap’s get_used_cells() function to perform some game logic.
On my card object, I store a “old_tilemap_coords” variable, keeps track of the tilemap coordinates of the card.
I thought I might be able to do something like this:
# Assume "coord" is the new position where the tile is to be placed.
# Assume "item" is a reference to the selected card object
# place it in the new position
set_cell(coord,
get_cell_source_id(card.old_tilemap_coords),
get_cell_atlas_coords(card.old_tilemap_coords),
get_cell_alternative_tile(card.old_tilemap_coords))
# now remove the cell from the old position
erase_cell(item.old_tilemap_coords)
This does update the get_used_cells() result, but the card is effectively replaced with a new node, which has different properties.
This is fine, set_cell() doesn’t specify that it can reference things like this.
So to solve my problem, is my only option to write some method to copy over the relevant data properties of the source node and then apply them post the erase_cell() procedure?
# Assume "coord" is the new position where the tile is to be placed.
# Assume "item" is a reference to the selected card object
var some_var = item.some_data
# place it in the new position
set_cell(...)
# now remove the cell from the old position
erase_cell(item.old_tilemap_coords)
# Now re-apply data from original card
for i in range(CardRack.get_child_count()):
if CardRack.get_child(i) is CardBase:
if CardRack.get_child(i).coordinates == coord:
CardRack.get_child(i).some_data = some_var
Or is there something built in that I am not aware of that might make my life easier?