0 votes

Let's say there is a TileMap, the cell size is 32x32.
TileMap has a one-cell tile (32x32) and a four-cell tile (64x64).
If you call the get_used_cells () method, then for a 64x64 tile it will return only one cell, instead of four.
Is there a ready-made way to get a complete list of used cells, taking into account the size of the tile?

Тайлы разного размера на TileMap
Допустим, есть TileMap, размер ячейки равен 32х32.
У TileMap есть тайл размером в одну ячеку (32х32) и тайл размером в четыре ячейки (64х64).
Если вызвать метод get_used_cells(), то для тайла 64х64 он вернет только одну ячеку, вместо четырёх.
Есть ли готовый способ получить полный список используемых ячеек с учётом размеров тайла?

Godot version 3.2.3
in Engine by (42 points)

1 Answer

+1 vote
Best answer

Not really. From the point of view of tilemap, the 2x2 tiles are just regular 1x1 tiles with texture spilling into neighboring tiles. There is no build in concept of tiles that span multiple cells. You can keep a list of which tile indices are actually 2x2 and make a custom get_used_cells()method that adds the missing cells. For example like this:

var list_of_2x2_tiles = [1, 5, 8 ] #contains tile indices of 2x2 tiles
func get_used_cells_incl_2x2() 
     var used_cells = get_used_cells()
     for id in list_of_2x2_tiles:
         for cell in get_used_cells_by_id(id):
             #assuming the tile is top-left corner
             used_cells.push_back(cell + Vector(1,0))
             used_cells.push_back(cell + Vector(0,1))
             used_cells.push_back(cell + Vector(1,1))
    return used_cells
by (168 points)
selected by

Thanks, I did something like this)
It's a bit sad that there is no built-in method (

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.