2

我正在使用 pygame 和 Tiled 制作游戏来设计地图。我能够加载瓷砖并将它们粘贴到屏幕上。当我水平翻转瓷砖/在 Tiled 内旋转并运行游戏时,瓷砖不会在游戏内旋转。

所以我想在将瓷砖贴到屏幕上之前检查瓷砖是否旋转/翻转,我不知道该怎么做,或者这是否可能并继续使用瓷砖而没有任何旋转或翻转平铺?

我读到有你可以检查的标志,但在这一点上我也不确定,任何帮助都会很棒。这是用于制作地图的类

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

水平翻转的同一个图块如何出现在 Tiled 内部

我运行游戏时如何加载图像


好的,在阅读Tile flipping之后,这就是我从中理解的内容。

  • 获取gid

从这段代码中已经有了for x, y, gid, in layer:

  • 检查标志

gid 的最高三位存储翻转的状态。

说第 32 位用于水平翻转。所以要检查我们所做h_flipped = gid & (1<<31) # correct?的但这里的问题是当我这样做时它评估为 a 0。打印出未翻转1瓷砖和2翻转瓷砖的 gids2 & (1<<31) # false

伪代码有点混乱,也许我理解不正确。所以要么我得到的gids不正确,要么检查位不正确?或两者?更多帮助表示赞赏

4

0 回答 0