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")
你可以簡單地做到這一點'回報'聲明。 –