0 votes

I want to add building to my game, so I need to have tiles that change when you click on their spot in the game.

Godot version 3.3
in Engine by (14 points)

Are you using a TileMap?

1 Answer

0 votes

Hi,

Your title states something different from your explanation. Do you need to add a tile or to change a tile?

Changing a tile is quite easy, you just need to get the coordinates of your mouse on a click event. With world_to_map() you can convert it to your tilemap and get the corresponding cell. You can now change the cell.

On my projects, I build my tilemap based on a dictionary (each cells has properties, like which building is on it, etc.). So I only have to get the cell coordinates, update the dictionary on the corresponding cell, and reload the map.

Adding a tile is something I have not done yet, but it seems doable : you can get_used_cells() check is the click event is on an existing cell or not. If not, you can add the cell definition in the dictionary on which you can base your tilemap for instance, and add properties.

Hope it helps.

by (80 points)
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.