Tile access problem

I want to get the count for all tiles in a layer, then cycling through all this tiles and checking for on screen collisions with an object. How can I best do this. The documentation just allows to get tiles by looking at coordinates… but that’s not what I need. I just want to work with a table of all the tiles in a layer to do a check.

Hey,

I don’t no in what kind of format the tile table is in.

I assume it’s a table that contains subtables for each row, which contain tile entrys for each x cordinate?

If that’s the case, why not just using a nested pairs loop?

You could do as @torbenratzlaff mentioned (the table is named layer.tiles and the tiles are stored layer.tiles[x][y]), or you could just do a numChildren loop:

for i = 1, layer.numChildren do local tile = layer[i] -- If you need the tile's tile position, it's stored as tile.tileX/Y end

If you’re inserting other objects into the tile layer, be sure to add a check to make sure the object you’re iterating is a tile.

  • Caleb

Thank you for the detailed help here! I really appreciate it!

Hey,

I don’t no in what kind of format the tile table is in.

I assume it’s a table that contains subtables for each row, which contain tile entrys for each x cordinate?

If that’s the case, why not just using a nested pairs loop?

You could do as @torbenratzlaff mentioned (the table is named layer.tiles and the tiles are stored layer.tiles[x][y]), or you could just do a numChildren loop:

for i = 1, layer.numChildren do local tile = layer[i] -- If you need the tile's tile position, it's stored as tile.tileX/Y end

If you’re inserting other objects into the tile layer, be sure to add a check to make sure the object you’re iterating is a tile.

  • Caleb

Thank you for the detailed help here! I really appreciate it!