some logic for going through the layers in tiled