Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Support #171

Open
JiffyRob opened this issue Jan 22, 2023 · 2 comments
Open

Template Support #171

JiffyRob opened this issue Jan 22, 2023 · 2 comments

Comments

@JiffyRob
Copy link

JiffyRob commented Jan 22, 2023

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 a TiledTemplate 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).

@JiffyRob
Copy link
Author

JiffyRob commented Jan 22, 2023

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.

@drvolk
Copy link

drvolk commented Feb 14, 2023

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants