AtlasTexture

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

I want to get my x and y coordinates reporting an index.
For example, I have an image of 500 x 500, and tiles of 50 x 50, so I have 10 tiles in the rows and 10 in the columns, then having 100 tiles of 50x50 in all.
So if I wanted to get my tile 10, I would create a Rect2(0, 50, 50, 50), assuming it starts at 0,0!
More than mathematical formula or gdscript method I can use for this

:bust_in_silhouette: Reply From: exuin

If you want to get an index from the coordinates of a tile, then it’s

x/num_cols + y/num_rows * num_cols

Where all division is integer division (rounds down). The Rect2 of the tile would be

Rect2(i%num_rows * col_width, i/num_rows * row_length, tile_width, tile_length)

very thank you

GuilhermeA | 2021-02-27 16:12