I'm working on a platform game and I'm a little stuck on the map building part. I've already got a working example that takes a set of tiles and draws a map with them, but it only works if all the tiles are aligned in one row on the same tile sheet. This is fine for my test level, which only has 4 different tiles, but I'm planning on making bigger and more complex maps with 50 or more different tiles.

Is there a way I can make an array that will store the x and y position of each tile? If not, what other method should I use? An XML file maybe? I'd also like to be able to group similar tiles together in their own tile sheets - grass/trees/bushes in one, dirt/stone/sand in another, etc. How would I tell the map builder function which tile sheet the tile is in, though?