–1 vote

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

in Engine by (20 points)

2 Answers

–2 votes
Best answer

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.

by (440 points)
selected by
–1 vote

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

by (884 points)
reshown by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.