我正在开展一个名为“Aûbys图例”的项目。在这个游戏中,有很多图片需要加载。所以,我试图减少其他函数中的Pygame.load函数。
def Load(current,c):
global current_load # crurent load is used after, outside the function
current_load = str(current) + '.png'
if c == 1:
Window('load') # it's add progress on the bar && show the progress
elif c == 2:
Window('first_load') # it's initialize the progress bar && add progress
p_load = pygame.image.load(current_load).convert_alpha()
return p_load
bg32 = Load(bg32,0) #take the value of p_load
但是当我在我的代码上尝试它时,回溯给我一个错误:
Traceback ( most recent call ):
.../test.py, line 81, in <module>
background = Load(bg32,0)
NameError : name 'bg32' is not defined
有谁可以帮助我吗 ?
感谢Jasonharper解决这个问题:D
def Load(current,c):
global current_load # crurent load is used after, outside the function
current_load = str(current) + '.png'
if c == 1:
Window('load') # it's add progress on the bar && show the progress
elif c == 2:
Window('first_load') # it's initialize the progress bar && add progress
p_load = pygame.image.load(current_load).convert_alpha()
return p_load
bg32 = Load('bg32',0) #take the value of p_load