首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试在pyTMX中使用getTileImageByGid时出现AttributeError

尝试在pyTMX中使用getTileImageByGid时出现AttributeError
EN

Stack Overflow用户
提问于 2019-04-23 16:30:09
回答 1查看 116关注 0票数 0

我正在尝试为pyGame中的一个项目加载TMX映射。当我不添加对象时,地图加载得很好。我使用平铺来创建地图。当我这样做的时候,我会得到一个attributeError。

我曾尝试重新安装pytmx,并尝试使用其他地图,但似乎都不起作用。

代码语言:javascript
复制
def gameStart():
    game = True

    tm = pytmx.load_pygame('resources/maps/map1/map.tmx')
    size = tm.width * tm.tilewidth, tm.height * tm.tileheight

    tmx_data = tm

    tw = tmx_data.tilewidth
    th = tmx_data.tileheight
    gt = tmx_data.getTileImageByGid

    while game:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        if tmx_data.background_color:
            screen.fill(tmx_data.background_color)

        for layer in tmx_data.visibleLayers:
            if isinstance(layer, pytmx.TiledLayer):
                for x, y, gid in layer:
                    tile = gt(gid)
                    if tile:
                        screen.blit(tile, (x * tw, y * th))

            elif isinstance(layer, pytmx.TiledObjectGroup):
                pass

            elif isinstance(layer, pytmx.TiledImageLayer):
                image = gt(layer.gid)
                if image:
                    screen.blit(image, (0, 0))



        pygame.display.update()

        clock.tick(framerate)

这将返回以下内容:

代码语言:javascript
复制
File "main.py", line 45, in gameStart
    gt = tmx_data.getTileImageByGid
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytmx/pytmx.py", line 214, in __getattr__
    raise AttributeError
AttributeError
EN

回答 1

Stack Overflow用户

发布于 2019-04-24 01:38:37

读取documentation,它有不同的名称:get_tile_image_by_gid(gid)

下次您可以检查print( dir(tmx_data) )以查看tmx_data中的所有方法和属性

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55807159

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档