I want to be able to check whether certain tiles exist in my tilemap (for e.g. all tiles numbered 1 and 2). Could someone please point me towards the code to do this?
First grab the bounds with tilemap.get_bounds(), then iterate through all tiles with tilemap.get_tile().
I did just this the other day to be able to spawn game objects where certain tiles are. I then also use tilemap.set_tile() to clear the tile.
2 Likes
Hello! Thank you for your response. I checked out the links and understand that this code:
local x, y, w, h = tilemap.get_bounds("/level#tilemap")
will give me four numbers in x,y,w,h. I understand what each letter represents but, I’m not getting how to loop in them
Try something like:
local start_x, start_y, w, h = tilemap.get_bounds("/level#tilemap")
for x=start_x,start_x+w do
for y=start_y,start_y+h do
print(tilemap.get_tile("/level#tilemap", "layer1", x, y))
end
end
2 Likes
It worked! Thank you so much.
1 Like