So I'm making a game to test my programming skills and I'm trying to use pygame but when i try and load a level map it says the surface has quit. I have no idea why.
This is the load code:
def load(self):
print(os.listdir())
file = input('>>> file name = ')
try:
self.Dir = os.getcwd()
path = os.path.join(self.Dir, "maps", file)
data = pickle.load(open(path, 'rb'))
except OSError as error:
print('Not file ', path)
print(error)
else:
self.grid = data[0]
self.blocks = data[1]
Thanks in advance
EDIT: this is the trace back
Traceback (most recent call last):
File "F:\PROGRAMS\snow\mapmaker_v2.py", line 169, in <module>
a.loop()
File "F:\PROGRAMS\snow\senpy.py", line 95, in loop
self.blocks.draw(self.screen)
File "F:\BMDSIT\Portable Python 3.2.5.1\App\lib\site-packages\pygame\sprite.py", line 475, in draw
self.spritedict[spr] = surface_blit(spr.image, spr.rect)
pygame.error: display Surface quit
EDIT 2: This is the loop code where it happens:
(The load command is in the self.keyboard() function.)
def loop(self):
print('looping')
for event in pygame.event.get():
if event.type == pygame.QUIT:
print('quiting :(')
pygame.display.quit()
quit('User quit')
self.screen.fill((237, 237, 237))
self.keys = pygame.key.get_pressed()
self.mos = pygame.mouse.get_pressed()
self.mouse()
self.keyboard()
#screen.blit(player,player.pos)
self.blocks.draw(self.screen)
self.extraLoop()
pygame.display.flip()
print('done looping')
You can't pickle a Surface
object.
If you want to pickle an object that contains a Surface
, remove it before saving it to disk; and store the name of the image file or a string representation of the Surface
instead in the object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.