0 votes

I want to create a simple, 2-D sandbox game where the player is able to place and remove tiles in the game world. Each unique type of tile to be able to drop different items (similar to Terraria). How shoud I go about doing this? Would a TileMap node work, or should I use individual StaticBodies, etc? How can I implement placing/breaking tiles? Thanks in advance for any help!

asked Jun 13 in Engine by redstonecreeper8 (21 points)

1 Answer

+1 vote
Best answer

The class TileMap, and its TileSet resource, have several properties and functions to be used from script, including:
You can refer to a tile with its Id (which is unique) or the name you gave it when creating it.
You can exchange one tile for another or delete it. You can change entire groups if you use this in a loop or you can generate random tiles -> procedural maps!
You can pass world coordinates (pixels) to tilemap coordinates (tiles) and vice versa for example, to detect in which tile is the mouse pointer.
The tiles can carry collisions, navigation, etc. You can also animate them, but I don't know how, one way is with an AnimateTexture, for example to show the frames of a block that is breaking. I believe that with TileMaps you can do what you want, and obviously combining it with other godot nodes for specific parts like static bodies as you said. Study the TileMap and TileSet documentation and search godot tutorials with words like terraria, minecraft, procedural maps etc.

answered Jun 13 by estebanmolca (1,199 points)
selected Jun 13 by redstonecreeper8
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.