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!

in Engine by (67 points)

1 Answer

+2 votes
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.

by (2,260 points)
selected 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 Frequently asked questions and 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 [email protected] with your username.