I have done tiled maps and tile sets quite often, but in a rather simplified way. My tile sets were linear images of the size (tile_width * num_tiles) * tile_height, so I could find an index easily by using val src_pos = (index * tile_width, 0).
But in reality, I've come to notice, tile sets are actually fully sized images of two dimensions. That has some advantages, clearly, it's easier to draw. So I wanted to support that. The problem would be just to turn the index to the right source position. Failed a bit, so I wanted to ask here.
I've had two ideas dealing with it:
Turn the index into two values with
src_x = index modulo num_tiles_x
src_y = index div num_tiles_y
which lead me to some quite weird results. The tiles are correctly cut, but they're the wrong ones for the position.
The other idea is to take the image and turn it into a 1D-tile set by cutting it up. But I am afraid that would not be an option, as I am using Textures.
How is this solved in 'professional' applications?