Accessing image path in c++

Hi,
a while ago I posted this topic:

Basically what I do is add a custom “pathImage” property that I can later retrieve in c++ doing this:

auto layer = Layer::create();
TMXObjectGroup* tmxObjGroup = tileMap->getObjectGroup("myLayerName");  
for (auto obj : tmxObjGroup->getObjects())                         
{                                                                  
    auto dict = obj.asValueMap();
    auto spriteImagePath = dict["imagePath"].asString();
    
    //...
}

This was fine until it became hard to manage. Is it possible to access the image path without the need of any custom attribute where I set it manually?
@eishiya mentioned in the previous post : “resolve object types and properties” export option to explicitly set inherited value”, mentioning as well to be careful not overwriting the working file. So I didn’t explored that any further just in case.

Simply put, back to the original question. Can I access by default the image path of the images of an object layer?

Thanks

The option to resolve properties basically explicitly writes out even default values into your exported file. The warning about not overwriting the existing file just meant to export the map with the resolved properties to a different file path than your working copy, but if you ever did overwrite your working map you should be able to revert it using version control .

The other option you could go for instead of exporting your map with properties resolved is to read your tiled project file and parse out the property types and their default values. Then when you are reading your map files, write code to fill in any default values for the given class/type for any properties that don’t already have a value. This saves you from needing multiple copies of your map files.

1 Like

You can also export your custom type definitions and read that instead of the project file. If you’re reading this data at runtime rather than just at build-time, you probably wouldn’t want to ship your entire project file with your game. The downside to exporting the custom type definitions is you have to remember to do so if you change them.

Another option: Have your Tiled defaults match your engine/game defaults, so that you neither need to read nor export the default values. This does require that you set some useful defaults in-engine, and it does mean that might have to set more properties in Tiled than you otherwise might, but this is the approach I’ve found most convenient for my projects.

2 Likes

Ok cool.
I’ll give that a try. Thanks