Is it possible to only show a region of a tilemap?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By offbeatoctopus
:warning: Old Version Published before Godot 3 was released.

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?

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.

quijipixel | 2017-09-10 13:34

:bust_in_silhouette: Reply From: BE-Never Games

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 :slight_smile: