Python 我的pygame窗口显示“我的pygame”;“没有回应”;当我使用collidepoint()时
我想做一个游戏。在我的游戏中有一个商店和战斗模式。当我使用Python 我的pygame窗口显示“我的pygame”;“没有回应”;当我使用collidepoint()时,python,pygame,Python,Pygame,我想做一个游戏。在我的游戏中有一个商店和战斗模式。当我使用collidepoint()时,如果collidepoint()为True,则它调用一个函数。但当我调用函数时,窗口会显示,不重新发送。我想不出这个问题,希望你能解决 def lvl1(): screen.blit(stickmanlvlim,(0,0)) pygame.display.update() def lvl2(): screen.blit(stickmanlvlim,(0,0)) pygame.
collidepoint()
时,如果collidepoint()
为True
,则它调用一个函数。但当我调用函数时,窗口会显示,不重新发送。我想不出这个问题,希望你能解决
def lvl1():
screen.blit(stickmanlvlim,(0,0))
pygame.display.update()
def lvl2():
screen.blit(stickmanlvlim,(0,0))
pygame.display.update()
def lvl3():
screen.blit(stickmanlvlim,(0,0))
pygame.display.update()
def fight(events):
lvl1R = pygame.Rect((20,335),(50,50))
lvl2R = pygame.Rect((170,335),(50,50))
lvl3R = pygame.Rect((320,335),(50,50))
world1setup()
fight = True
while fight:
for event in events:
if event.type == pygame.QUIT:
fight = False
if event.type == pygame.MOUSEBUTTONDOWN:
spot2 = pygame.mouse.get_pos()
if lvl1R.collidepoint(spot2):
lvl1()
if lvl2R.collidepoint(spot2):
lvl2()
if lvl3R.collidepoint(spot2):
lvl3()
问题出在
fight()
函数中。没有错误。尝试在不同的函数中调用事件,例如:
def fight(events):
lvl1R = pygame.Rect((20,335),(50,50))
lvl2R = pygame.Rect((170,335),(50,50))
lvl3R = pygame.Rect((320,335),(50,50))
world1setup()
fight = True
while fight:
spot2 = pygame.mouse.get_pos()
if lvl1R.collidepoint(spot2):
lvl1()
if lvl2R.collidepoint(spot2):
lvl2()
if lvl3R.collidepoint(spot2):
lvl3()
def main():
run = True
while run:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
run = False
elif event.type == pygame.MOUSEBUTTONDOWN:
fight(events)
main()
不要忘记在while循环的开头添加
pygame.event.get()
。欢迎使用堆栈溢出。你能提供一份报告吗?如果有人需要看更少的代码,他们会更容易帮助你。您需要删除与问题无关的代码行,以便其他人可以关注重要部分。听起来不错!!!!那没用,它还是会卡住。我不知道它为什么一直被卡住。试着在while循环的开头调用'''pygame.event.get()''。