我正在从事一个名为“ TheAûbysLegend”的项目。 在此游戏上,有很多图片需要加载。 因此,我尝试将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
有人可以帮我吗?
答案 0 :(得分:0)
感谢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