How do I use Tiled custom properties?

I’ve been following this tutorial on how to make a turret defence game. I understand most of it but I’m having a lot of trouble using Tiled’s custom properties.

I have a tile with the property “buildable” and the value “True”. I want to check the value is true before I can add a tower using the method canBuildOnTilePosition() as shown in the tutorial.

Can anyone give a code snippet or explain how to get the property, and the value?

I can post code to show how I’ve been trying to do it if it helps.

Cpp-test contains many things. You should read the TileMapTest part.

TMXOrthoObjectsTest::TMXOrthoObjectsTest()
{
    auto map = TMXTiledMap::create("TileMaps/ortho-objects.tmx");
    addChild(map, -1, kTagTileMap);

    auto group = map->getObjectGroup("Object Group 1");
    auto& objects = group->getObjects();

    Value objectsVal = Value(objects);
    CCLOG("%s", objectsVal.getDescription().c_str());
    
    for (auto& obj : objects)
    {
        ValueMap& dict = obj.asValueMap();
        
        float x = dict["x"].asFloat();
        float y = dict["y"].asFloat();
        float width = dict["width"].asFloat();
        float height = dict["height"].asFloat();

    }
}
2 Likes

Nice one, didn’t realise the test classes had that much extras. Looking into it now but I think it’s something different I’m looking for.

Nice one, didn’t realise the test classes had that much extras. I’m trying to use the tile layer to get the custom properties of the tile rather than see if there’s an object there. I might try adding objects over the turret positions and test for them to add a tower.