how can i to interact with tiles

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ktotoetoia

Hello everyone, I would like to know how you can interact with tiles, for example, so that when you click on a tile, it changes color, I need this to create a turn-based strategy, thanks

:bust_in_silhouette: Reply From: Help me please

Hello!
Please check out this tutorial
https://godottutorials.pro/godot-strategy-game-tutorial/

:bust_in_silhouette: Reply From: Merlin1846

The tutorial the person linked to doesn’t use the tile map. It instead uses a ridiculously inefficient and cpu heavy custom set up.

But to answer your question, say when you click a tile at position Vector2(0,0) you want it to turn orange from red, well your going to need 2 tiles a orange one and a red one, using the editor set the tile at 0,0 to be the red one.

func _physics_process(delta):
 if Input.is_action_just_pressed("click"):
  $tile_map.set_cell($tile_map.world_to_map(get_global_mouse_position()),1)

this assumes that your tile map node is a child of the node with the script and that the orange tiles id is 1 and that you have a input named click that activates when you click.

But what this will do is it will set the tile at the location of the mouse to id 1, which in this case is the orange tile. You could set it up so that it instead sets it to a id stored in a variable.

If you just want a overlay type thing then consider making a sprite with a picture that matches the overlay and making it slightly transparent, that could do if your looking for that.