Skip to content

Conversation

@pnearing
Copy link

I expanded TiledObject to recognize ellipses, text and points. I added a new property to the object called object_type which is meant to be a literal string, currently it will be one of "rectangle", "text" "polygon" "polyline", "ellipse", and "point".

Also my IDE cleaned up and made some date changes.

Changed the copyright years in multiple files for consistency. Adjusted object types in `pytmx.py` to include additional types such as ellipse, point, and text, along with their respective attributes. Refined imports and typing hints across various modules for clarity and efficiency.
Changed all single quotes to double quotes for string literals in pytmx.py. This ensures uniformity in the codebase and improves readability and maintainability of the code. No functional changes were made.
@joereynolds
Copy link

Hmm, those changes made by your IDE are a bit suspect

They've changed the copyright years to be in the past. What's worse though is that they've removed the return typehints which are useful for people working with PyTMX

@pnearing
Copy link
Author

I didn't notice the type hint changes. I'll go through them and check it out, I'm all about typing.

Introduce a new method, get_tile_flags_by_gid, to fetch tile flags using the global tile ID (GID). This improves the convenience of accessing tile properties directly by their GID.
@pnearing
Copy link
Author

Okay, I've removed the changes my IDE made, and left only the object changes, also I added a function called get_tile_flags_by_gid to get the flags of a gid, I use this for correctly flipping and rotating my colliders.

Copy link

@zommerfelds zommerfelds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving some drive-by comments :)

I was about to make the same changes, so let's try to get this PR in, it's useful!

@zommerfelds
Copy link

zommerfelds commented Apr 13, 2025

BTW I switched to using @pnearing's repo for my project, and it does work.

One thing to note is that images/tiles are considered rectangles. Which is not wrong, as you can use the gid property to distinguish, but we could consider setting the object_type to tile.

@zommerfelds
Copy link

Sorry to add yet another comment, but another thing that would be convenient is if rectangles also had points generated... (future follow-up)
Meanwhile I'll have to manually convert from rectangle to points, so I can draw using the same polygon function.

@pnearing
Copy link
Author

Sorry to add yet another comment, but another thing that would be convenient is if rectangles also had points generated... (future follow-up) Meanwhile I'll have to manually convert from rectangle to points, so I can draw using the same polygon function.

If you happen to still be using my repo, I added points for rectangles.

@JaskRendix
Copy link
Contributor

@pnearing hey man, since you're working on that section already, would you mind swapping this piece out while you're in there?

        if points:
            x1 = x2 = y1 = y2 = 0
            for x, y in points:
                if x < x1:
                    x1 = x
                if x > x2:
                    x2 = x
                if y < y1:
                    y1 = y
                if y > y2:
                    y2 = y
            self.width = abs(x1) + abs(x2)
            self.height = abs(y1) + abs(y2)

with this

        if points:
            xs, ys = zip(*points)
            self.width = max(xs) - min(xs)
            self.height = max(ys) - min(ys)

@pnearing
Copy link
Author

Done.

@pnearing
Copy link
Author

To anyone who may be using my version of pytmx, I forked the project as pytmx-ng and will be happy to maintain it. the new code can be found here: https://github.com/pnearing/pytmx-ng

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

Successfully merging this pull request may close these issues.

4 participants