我正在使用pygame和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))
水平翻转的相同平铺在平铺中的显示方式
当我运行游戏时图像是如何加载的
好的,在阅读了Tile flipping之后,以下是我从中了解到的
已经从这段代码中得到了for x, y, gid, in layer:
The highest three bits of the gid store the flipped states.
表示第32位用于水平翻转。为了检查我们是否做了h_flipped = gid & (1<<31) # correct?
,但这里的问题是当我做的时候,它的计算结果是0
。打印出GID会为未翻转的磁贴提供1
,为翻转的so提供2
伪代码有点混乱,可能我理解不正确。所以要么我得到的GID不正确,要么检查位不正确?或者两者都有?多谢帮忙
目前没有回答
相关问题 更多 >
编程相关推荐