# Converting single number to tileatlas coordinates [duplicate]

I'm trying to make a 2d tilemap based platformer, but I don't know how to convert single numbers to a tilemap coordinate. Imagine a map:

map = [[10, 12, 24],[12, 14, 5],[13, 011, 19]] (numbers are exaggerated for this example)

and for each number I have a corresponding asset in the tileatlas. The tileatlas holds tiles which are 16x16 pixels and is 64 pixels wide, so every 4th number I need to step down 16 pixels.

I'm sure there's a way to do this, and if not, do you guys know a better way of handling tiles?

I also don't know if this is a duplicate because all my keywords redacted to nothing, so sorry if it is

• It's not clear to me what the triples in the map array you've shown, or the single number you're describing, actually represent. Can you explain in more detail? (eg. "My coordinates are measured as the number of pixels from the top-left of the map to the top-left of the tile" etc) Remember, numbers are very versatile things, so games have used them in many many different ways which might be different from the convention you're using in your game. It might help to include a diagram showing your coordinate grid with some example input numbers and the coordinates they should map to. Sep 1, 2021 at 18:24
• Sorry, I want to have a single number in the map associated with a texture in the atlas, to keep the map clean, but if I do it that way I get problems with figuring out the x and y locations... It's not really about the x and y in rendering, but to sample the image from the tilemap, like: tilemap.getTile(16, 32) Sep 1, 2021 at 18:27
• Are you looking for Calculate position on Tile Map by single index? Sep 1, 2021 at 18:29
• Yes, thank you so much! Now, since this is a duplicate, should I delete the post? Pretty new to stack... Sep 1, 2021 at 18:32
• Nah, we'll just mark it as a duplicate. Then it can show up in search hits for future users looking for the same keywords you used, and that hit can lead them to the existing answers via the duplicate link. Sep 1, 2021 at 18:33