Reputation: 57
I am trying to load a TMX map for a project in pyGame. The map loads fine when I don't add objects. I use Tiled to create the maps. When I do, I get an attributeError.
I have tried to reinstall pytmx and tried with other maps but nothing seems to work.
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)
Which returns the following:
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
Upvotes: 0
Views: 267
Reputation: 143216
Read documentation it has different name: get_tile_image_by_gid(gid)
Next time you can check print( dir(tmx_data) )
to see all methods and properties in tmx_data
Upvotes: 1