0

Basically I'm trying to make a title screen for a game I'm making and I hit a bit of a roadblock. Basically I have two buttons to far. One for a 'PLAY' button and the other for a 'QUIT' button. When I click the quit button I wrote down that it would make done = True. Since the loop needs done = False to do the loop. Here is my code:

done = False
 
# Used to manage how fast the screen updates
clock = pygame.time.Clock()
 
# Hide the mouse cursor
pygame.mouse.set_visible(False)
 
# -------- Main Program Loop -----------
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
 
        elif event.type == pygame.MOUSEBUTTONDOWN:
            # When the mouse button is pressed, see if we are in contact with
            # other sprites:

            start_block = pygame.sprite.spritecollide(player, start_block, True)
            if len(start_block) >= 1:
                   quitg.rect.x = 5000
                   logo.rect.x = 5000

            quit_block = pygame.sprite.spritecollide(player, quit_block, True)
            if len(quit_block) >= 1:
                done = True
            #print(score)
            #blocks_hit_list = pygame.sprite.spritecollide(player, block_list, True)
            #if len(blocks_hit_list) >= 1:
                #score +=1


            # Set the list of blocks we are in contact with as the list of
            # blocks being carried.
            #player.carry_block_list = blocks_hit_list
 
        elif event.type == pygame.MOUSEBUTTONUP:
            # When we let up on the mouse, set the list of blocks we are
            # carrying as empty.
            player.carry_block_list = []

 
    all_sprites_list.update()
    
 
    # Clear the screen
    screen.fill(WHITE)
 
    # Draw all the spites
    all_sprites_list.draw(screen)
 
    # Limit to 60 frames per second
    clock.tick(60)
 
    # Go ahead and update the screen with what we've drawn.
    pygame.display.flip()
 
pygame.quit()
  • It must be the case that both `if len(quit_block) >= 1` and `if event.type == pygame.QUIT:` are always evaluating to `False`. I'm thinking that the `spritecollide` is the issue here. You have `start_block = pygame.sprite.spritecollide(player, start_block, True)`, which uses `start_block` as an argument to itself, but you never defined `start_block` anywhere else. Same with `quit_block`. Unless your code is not a [mre], I don't see how that could ever work. Seeing as you haven't shared the definition of `all_sprites_list`, it seems that your example is indeed incomplete. – Random Davis Nov 23 '21 at 22:45
  • How often do you call `pygame.event.get()` in your application? See [Faster version of 'pygame.event.get()'. Why are events being missed and why are the events delayed?](https://stackoverflow.com/questions/58086113/faster-version-of-pygame-event-get-why-are-events-being-missed-and-why-are/58087070#58087070). – Rabbid76 Nov 24 '21 at 05:39

0 Answers0