Aus irgendeinem Grund kann ich diese Schleife nicht beenden, wenn ich zu intro = false ändere, kann jemand helfen, wie ich diese If-Anweisung beenden würde. Es ist mein Menü-Bildschirm, und sobald ich auf "neues Spiel" klicke, möchte ich, dass es die Funktion game_intro verlässt. DieseBeenden von If-Anweisung Schleife Python
ist, wo ich definieren 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")
Dies ist, wo ich die Tastenfunktion erstellt:
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
und das ist, wo ich auf die Funktion aufrufen:
while intro == True:
game_intro()
print("loopexited")
können Sie einfach tun, indem 'Rückkehr 'Aussage. –