0

just trying to load a layer from my tilemap in for collision detection, but having problems. Apparently it tells me my layer is out of range.

 private void getTiles(int startX, int startY, int endX, int endY, Array<Rectangle> tiles) {
    TiledMapTileLayer layer = (TiledMapTileLayer)map.getLayers().get("layer2");
    rectPool.freeAll(tiles);
    tiles.clear();
    for(int y = startY; y <= endY; y++) {
        for(int x = startX; x <= endX; x++) {
            Cell cell = layer.getCell(x, y);
            if(cell != null) {
                Rectangle rect = rectPool.obtain();
                rect.set(x, y, 1, 1);
                tiles.add(rect);
            }
        }
    }
}

I've also tried putting just the integer in as well, same result, only one that works is 0. My .tmx map in Tiled has two layers, "layer1" and "layer2". The map displays fine, so I know I've loaded the .tmx correctly (used the TmxLoader to create a TiledMap called "map"). Not sure what's going on.

Daahrien
  • 10,190
  • 6
  • 39
  • 71

0 Answers0