0
出于某种原因,我不能退出这个循环,当我改变为intro = false,任何人都可以帮助我如何退出这个if语句。这是我的菜单屏幕,一旦我点击“新游戏”,我希望它退出game_intro功能。退出如果语句循环python
这是我定义game_intro:
def game_intro():
intro = True
if intro == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
window.fill(superlightgrey)
fontvertical = pygame.font.SysFont("comicsansms", 100)
text = fontvertical.render("Connect 4", True, skyblue)
word = (10, 1)
window.blit(text,word)
ButtonIntro("New Game", 340, 140, 200, 50, superlightgrey, superlightgrey, "Play")
这是我创建的按钮功能:
def ButtonIntro(msg, x, y, w, h, ic, ac, action=None):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if x+w > mouse[0] > x and y+h > mouse[1] > y:
pygame.draw.rect(window, ac, (x, y, w, h))
if click[0] == 1 and action != None:
pygame.draw.rect(window, lightgrey, (x, y, w, h))
if action == "Play":
intro = False
##WHAT DO I NEED HERE TO EXIT LOOP
而这正是我呼吁函数:
while intro == True:
game_intro()
print("loopexited")
你可以简单地做到这一点'回报'声明。 –