所以我有一个名为Images
的字典,它存储pygame.Surface
对象。我不需要每次运行代码时都需要构建整个字典,我只想从文件中读取它。腌制一个包含pygame的字典。表面物体
这是我试图用咸菜和unpickle字典代码:
with open('Images.pkl', 'wb') as output:
pickle.dump(Images, output, pickle.HIGHEST_PROTOCOL)
with open('Images.pkl', 'rb') as input:
Images = pickle.load(input)
后来,我用这个代码:
class Survivor:
def __init__(self):
self.body_image=Images['Characters/Survivor/handgun/idle0']
self.body_rect=self.body_image.get_rect()
这给了我:
File "ZombieSurvival.py", line 1320, in init self.body_rect=self.body_image.get_rect(center=self.vector)
pygame.error: display Surface quit
那么,有没有一种方法来调用'SDL_CreateRGBSurface()将在unpickle时'功能? –