所以我有一個名爲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時'功能? –