Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'get' #82

Closed
Filfire09 opened this issue May 27, 2017 · 9 comments
Closed

AttributeError: 'NoneType' object has no attribute 'get' #82

Filfire09 opened this issue May 27, 2017 · 9 comments

Comments

@Filfire09
Copy link

I was trying to use pytmx version 3.20.17 and while running code I've been getting this error

Traceback (most recent call last):
File "/Users/fpoadmin/Desktop/pygameimages/camera.py", line 17, in
gameMap = pytmx.load_pygame('images/map RPG3.tmx')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pytmx/util_pygame.py", line 116, in load_pygame
return pytmx.TiledMap(filename, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pytmx/pytmx.py", line 285, in init
self.parse_xml(ElementTree.parse(self.filename).getroot())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pytmx/pytmx.py", line 319, in parse_xml
self.add_layer(TiledImageLayer(self, subnode))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pytmx/pytmx.py", line 1110, in init
self.parse_xml(node)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pytmx/pytmx.py", line 1129, in parse_xml
self.source = image_node.get('source')
AttributeError: 'NoneType' object has no attribute 'get'

code

There is my code:

import pygame
import pytmx

pygame.init()

display_width = 800
display_height = 800

white = (255, 255, 255)

gameScreen = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('2d Game')
clock = pygame.time.Clock()

gameMap = pytmx.load_pygame('images/map RPG3.tmx')

def game_loop():
gameExit = False
while not gameExit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True

for layer in gameMap.visible_layers:
for x, y, gid, in layer:
tile = gameMap.get_tile_image_by_gid(gid)
gameScreen.blit(tile, (x * gameMap.tilewidth,
y * gameMap.tileheight))
pygame.display.update()
clock.tick(30)

game_loop()
pygame.quit()

The code did not really matter because I tried it with other codes and it would give the same error.

Please help me.

@bitcraft
Copy link
Owner

bitcraft commented May 27, 2017 via email

@Filfire09
Copy link
Author

Unfortunately, this site does not support TMX file I can't attach it....

@bitcraft
Copy link
Owner

bitcraft commented May 28, 2017 via email

@Filfire09
Copy link
Author

I'm sorry what's a pastebin ? ;/

@bitcraft
Copy link
Owner

bitcraft commented May 28, 2017 via email

@Filfire09
Copy link
Author

map RPG3.tmx.zip
Well actually I'll send you this zip file tell me if it works.

@bitcraft
Copy link
Owner

bitcraft commented May 28, 2017 via email

@bitcraft
Copy link
Owner

@Filfire09 has your issue been solved?

@Jonatan00x
Copy link

As for me deleting empty object layer solved the problem.
I have got an attribute error raised in getattr in TiledElement class.
Now it works.

@bitcraft bitcraft closed this as completed Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants