Ucy
Ucy

Reputation: 21

Does pytmx provide you with a way to tell if an image has been rotated, flipped horizontally/diag working with Tiled?

I am making a game using pygame and Tiled to design the map. I am able to load the tiles and blit them on to the screen. When i flip the tile horizontally/rotate inside of Tiled and run the game, the tiles are not rotated inside of the game.

So i would want to check if the tile is rotated/flipped before blitting the tile onto the screen and i am not sure how exactly to do this or whether if this is even possible and proceed to use the tiles without any rotations or flips inside of Tiled?

I read that there are flags you can check for, but at this point i am not sure of that either, any help would be great. Heres the class used to make the map

import pytmx

class TiledMap:
    def __init__(self, filename):
        tm = pytmx.load_pygame(filename)
        self.width = tm.width * tm.tilewidth
        self.height = tm.height * tm.tileheight
        self.tmxdata = tm

    def render(self, surface):
        ti = self.tmxdata.get_tile_image_by_gid
        for layer in self.tmxdata.visible_layers:
            if isinstance(layer, pytmx.TiledTileLayer):
                for x, y, gid, in layer:
                    tile = ti(gid)
                    if tile:
                        # check for flags first.. ie rotating, flips
                        # do the neccessary transformations... this part i know
                        # blit the transformed tile

                        # if no flags just blit the image
                        surface.blit(tile, (x * self.tmxdata.tilewidth,
                                                    y * self.tmxdata.tileheight))

how the same tile flipped horizontally appears inside of Tiled

how the image gets loaded when i run the game


Okay so after reading Tile flipping, here's what i understood from it.

Already have that from this bit of code for x, y, gid, in layer:

The highest three bits of the gid store the flipped states.

Says that 32nd bit is for horizontal flip. So to check for that we do h_flipped = gid & (1<<31) # correct? But the problem here is when i do that it evaluates to a 0. Printing out the gids gives 1 for the unflipped tile and 2 for the flipped so 2 & (1<<31) # false

The pseudo code was a bit confusing and maybe i understood it incorrectly. So either the gids i am getting is incorrect or the checking for the bit is incorrect? or Both? More help appreciated

Upvotes: 2

Views: 336

Answers (0)

Related Questions