tiled sprite algorithm