bitcraft / pytmx

Python library to read Tiled Map Editor's TMX maps.
GNU Lesser General Public License v3.0
384 stars 81 forks source link

Flags (such as rotation) not passed to image loader for multiple image tilesets #159

Closed scott-asdfasdf closed 1 year ago

scott-asdfasdf commented 2 years ago

Firstly, thanks for pytmx, it seems like it makes loading levels for a game much easier.

We were trying to use pytmx last week for a pyglet-based entry into pyweek last week, and I was trying to add support for rotations to the pyglet image loader, but I found the flags were not passed through at all, seemingly because my tilemap was multiple images.

Specifically, on lines 644 and 656 of pytmx.py (Current master at time of this report - https://github.com/bitcraft/pytmx/blob/2ef7dcac8526d9b5085c147b70b1078666542f12/pytmx/pytmx.py), the image loader is called without passing in any flags, so presumably rotations will be ignored for any library.

For our entry, I replaced the loader() call with the following:

                for gid, gids in self.gidmap.items():
                    for gid, flags in gids:
                        if gid == real_gid:
                            image = loader(flags=flags)
                            self.images[real_gid] = image

which seemed to fix rotation for me, but I imagine there's a less hacky way to do this?

bitcraft commented 2 years ago

The pyglet code is pretty old. I think the problem with it is that for pyglet is that its inefficient to handle the images like pygame. Pygame works better with images rotated ahead-of-time, but pyglet can easily rotate it at render time. So I kinda think that something in the pytmx API needs to change, so that rotation/transformation information can be iterated along with a texture.

bitcraft commented 2 years ago

But looking at the code here, I do see where the flags are not passed to the loader and that looks like a bug. Ill take a look, thanks for opening the issue.

bitcraft commented 1 year ago

please open a new issue and share the maps and images so i can take a look and help find a solution. closing for now.