The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

My game levels are made up of smaller, square-shaped, modular level blocks. I would like to be able to reuse blocks. I was using timemaps to build these blocks. Is there a way I can use a single tilemap to contain many blocks and instance in that tilemap and only show the block I want? Or do I have to create many tilemaps, each containing a block?

in Engine by (18 points)

I don't know if I understood what you want, but creating a scene with the tilemap as root might be the solution. You can add a script to this tilemap scene and add a method to show the block you want when the node is added to the game scene. You can use the tile map api to create the blocks you want.

1 Answer

0 votes

So basically you only want to show certain regions of your Map and be able to change the ones shown while playing the game, correct?
While you can not hide certain tiles you can set a specific tile using the method set_cell( int x, int y, int tile) (or alternatively set it using a Vector2 by calling set_cellv( Vector2 pos, int tile)). The first to parameters are the grid coordinates of said tile and the third one describes the index of the tile you want to use. Set this to -1 if you want to clear the cell.
You could create an array with a bunch of dictionaries at runtime which each hold the position and tile index of a tile. You can later iterate through this array and set all of the contained cells once you need them again.
Did that help you in any way? If you need clarification about anything, I would be happy to further explain :)

by (305 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 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.