Get amount of atlas tiles inside of a tile

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jujumumu

Is there a function in godot that can get the dimensions of the atlas tile. For example using tile_set.tile_get_region(id) gives the dimensions but in pixel size. But when you create an atlas tile you define a size of the grids(step). Is there a function to return the step? Then I could just use tile_set.tile_get_region(id)/get_step()

:bust_in_silhouette: Reply From: njamster

Is there a function to return the step?

This should do the job (if you know the id of your atlas tile):

get_node("TileMap").tile_set.autotile_get_size(id)

To then get the amount of tiles in the atlas you would do:

var region_size = $TileMap.tile_set.tile_get_region(0).size 
var subtile_size = $TileMap.tile_set.autotile_get_size(0)
var dimensions = region_size / subtile_size
var subtile_amount = ceil(dimensions.x) * ceil(dimensions.y)

Ceiling is important if your region isn’t perfectly aligned with the grid.

thanks! thats what i needed

jujumumu | 2020-04-01 20:48