0

So I am trying to make a game that operates using pygame, and I think there is an issue with display updating. Normally buttons work, but I think I am not formatting this correctly. Here is the relevant code:

while run:
    screen.fill((100,188,232))
    if game_paused:
         #Pause menu code
    else:
         Battle(team1,team2)
    #Working event handler
    clock.tick(60)
    display.update()

In battle function:

while neomon1.getHP() > 0 and neomon2.getHP() > 0:
            clock.tick(60)
            display.update()
            #Turn, may add turn counter?
            move1 = chooseMove(neomon1,screen)
            if twoplayer:
                move2 = chooseMove(neomon2,screen)

ChooseMove:

move1img = image.load("moveimg/"+str(neomon.getmove1().getID())+".png").convert_alpha()
    move2img = image.load("moveimg/"+str(neomon.getmove2().getID())+".png").convert_alpha()
    move3img = image.load("moveimg/"+str(neomon.getmove3().getID())+".png").convert_alpha()
    move4img = image.load("moveimg/"+str(neomon.getmove4().getID())+".png").convert_alpha()
    move1button = button.Button(10,370,move1img, 1)
    move2button = button.Button(360,370,move2img, 1)
    move3button = button.Button(10,550,move3img, 1)
    move4button = button.Button(360,550,move4img, 1)

    #Prototype 2: Hovering over moves code here
    chosen = False
    while not chosen:
        clock.tick(60)
        if move1button.draw(screen):
            chosen = True
            return neomon.getmove1()
        display.update()
        if move2button.draw(screen):
            chosen = True
            return neomon.getmove2()
        display.update()
        if move3button.draw(screen):
            chosen = True
            return neomon.getmove3()
        display.update()
        if move4button.draw(screen):
            chosen = True
            return neomon.getmove4()
        display.update()

At the moment, it displays the correct buttons, but then stops responding. I think it is to do with how I have formatted the subroutines with respect to Pygame. Current output Could someone help me out please?

Schmetris
  • 1
  • 2
  • You have to handle the events in the `while not chosen:` loop. See [`pygame.event.get()`](https://www.pygame.org/docs/ref/event.html#pygame.event.get) respectively [`pygame.event.pump()`](https://www.pygame.org/docs/ref/event.html#pygame.event.pump): *"For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system."* – Rabbid76 Oct 25 '22 at 10:45

0 Answers0