[Python] How can i blit buttons after pressing another button in pygame? [duplicate]

Discussão em 'Python' iniciado por Stack, Dezembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    I want to create a starting menu overlay that leads to level choosing option but when i click on the start button nothing will overlay

    Here is the important part of the code:


    [...]
    clicked=False
    [...]

    running=True
    while running:

    for event in pygame.event.get():
    if event.type==pygame.QUIT:
    running = False
    window.fill(black)

    pygame.draw.rect(window,title1_color,title1_rect)
    window.blit(title1_text,title1_text_rect)

    pygame.draw.rect(window,title2_color,title2_rect)
    window.blit(title2_text,title2_text_rect)

    pygame.draw.rect(window,title3_color,title3_rect)
    window.blit(title3_text,title3_text_rect)

    pygame.draw.rect(window,play_color,play)
    window.blit(play_text,play_text_rect)

    pygame.draw.rect(window,quit_color,quit)
    window.blit(quit_text,quit_text_rect)


    pos=pygame.mouse.get_pos()
    if play.collidepoint(pos):
    if event.type==pygame.MOUSEBUTTONDOWN:
    clicked=True
    if clicked==True:
    print("clicked") #Thats just for testing purposes
    window.fill(black)
    pygame.draw.rect(window,level1_color,level1)
    window.blit(level1_text,level1_text_rect)
    if event.type==pygame.mouse.get_pressed()[0]==0 and clicked==True:
    clicked=False


    if event.type==pygame.MOUSEBUTTONDOWN:
    if quit.collidepoint(pos):
    pygame.quit()

    pygame.display.update()



    I tried to put the "clicked" variable into the main game loop but that just created multplie clicks at ones and not just one as i want

    Continue reading...

Compartilhe esta Página