Open JiffyRob opened 1 year ago
I found a (partial) workaround - after you create the object and set your attributes, right click it and hit 'detach'. This will decouple it from the template and load all the inherited attributes directly. In order to "re-couple" it to the template you have to select it in the project view, right click the object in question, and select "replace with .tx". Sadly, you lose all overwritten data and have to re-enter.
I see it also like this, pytmx should provide a way to load the data from "TiledObject.template". I currently have the problem that I have used such templates for the definition of TileCollider shapes. Unfortunately pytmx does not take over the values for height and width from the template definition when initializing the TileCollider objects, so that these values are 0 and e.g. a correspondingly created Collider Rect() has no effect. Instead I have to load the ".tx" file from the "template" property itself and parse it to get the correct height and width of the Collider object for creating a corresponding Rect().
It looks like pytmx can't load templates.
When an object with a template is loaded, I see a
TiledObject.template
attribute which corresponds to the path of the template's.tx
file (relative to the path of the map), but there does not seem to be a way to get any meaningful data out of it without parsing the file separately, which (a) could generate a mess, and (b) really seems like it should be part of pytmx, since it takes care of everything else.The desired behavior would either be replacing the
TiledObject.template
attribute with aTiledTemplate
object or similar, or straight up overriding the object's attributes (most intuitive, in my opinion).Theoretically, adding support would not be too difficult. I'd be willing to try an implement it myself if necessary, but this seems to be a pretty simple feature to not have around. Am I missing something?
Here's my current tiled project as a test case. The assets are from here (CC0).