Is it for a "bomberman-like" rows and columns query?
Do you really want every single tile in the tilemap width and height?
Using get_used_cell()
, you can do this, but it will be slower on big tilemaps. If you have a small tilemap and you don't do this every frame, it should be ok:
func get_cell_row(tile_pos):
var row = []
var used_cells = tilemap.get_used_cells()
for cell in used_cells:
if cell.y == tile_pos.y:
row.append(cell)
return row
Alternatively, if you know the extents of your tilemap, you can do this instead, which is faster because it queries only a row instead of every tile:
func get_cell_row(tile_pos):
var row = []
for x in range(tilemap_min_x, tilemap_max_x):
if tilemap.get_cell(x, tile_pos.y) != -1:
row.append(Vector2(x, tile_pos.y))
return row
If you want tiles in a rectangular region, you need a different if test in the first version, and a double-for in the second version.
In your second code you used all.find(tile_pos,y)
, which is not going to do what you want. If it ever works, what it does instead is "find the index in the list at which the value tile_pos
is, ignoring all indexes before y
, then return it as an integer", which you aren't storing anyways. Not what you asked at all, right^^