How do you parse map layer of image based tiles using LIBGDX?

Hello,

I’m trying to parse an object layer of image based tiles for use in my 2d side scroller game using libgdx. I have already been able to parse in rectangle map objects just fine using the following code:

        ascendingPlatforms= Array<AscendingPlatforms>()
        for (object in map.layers.get("ascendingPlatformLayer").objects.getByType(RectangleMapObject::class.java)) {
            val rect = (object as RectangleMapObject).rectangle
            wheelPlatforms.add(WheelPlatforms(screen, rect.x / 100, rect.y / 100))
        }

However, when I try to perform a similar action to parse in tile map objects, I receive the following error:
“Exception in thread “LWJGL Application” java.lang.IllegalStateException: map.layers.get(“foregroundLayer”) must not be null.”

Here is the code i used to try to accomplish the tile map object layer parsing:

        foregroundImages = Array<ForegroundEnvironment>()
        for(object in map.layers.get("foregroundLayer").objects.getByType(TiledMapTileMapObject::class.java)) {
            val foreground = (object as TiledMapTileMapObject).tile
            foregroundImages.add(ForegroundEnvironment(screen, 1f, 1f))
        }

There are 10 tile objects in the layer I am trying to parse in and yet it cannot see them. How can i parse image based tile map objects as opposed to rectangle map objects, circle map objects, etc.?

It seems to be saying that it couldn’t find “foregroundLayer” in the layers. I don’t now this API, but check whether the name is really what you used in the map file. Also, it may not support grouped layers, so make sure this layer is not grouped within another layer.