1

Pygame is not updating the screen until some sort of input is detected. It should update when a certain value equals a certain number, but only actually does this when a key is pressed. This happens with every key that is pressed, not just the ones that actually do something. Is there a way to have the screen update without needing the user to cause the update?

I have looked at a previous post but no answer was ever approved by the original poster, and none work for me anyway. Screen only updates when I check for user input pygame

I appreciate any help given :D

The code detecting the value:

    if distance <= 25 and display_scroll[1] <= -135 and display_scroll[1] >= -250:
        print("scroll from man:", display_scroll[1])
        doSpeechMan = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_e:
                doText = True
                print("interact")
                teacherTalk = True
    if distance >= 25 and display_scroll[1] >= -135 and display_scroll[1] <= -250:
        doText = False
        doSpeechMan = False

The code that should update the screen:

if doSpeechMan:
    
    display.blit(pygame.transform.scale(bubble_image, (72, 72)), (50-display_scroll[0], 75-display_scroll[1]))
    ptext.draw("Press E", (60-display_scroll[0], 90-display_scroll[1]), color="black", fontname="text/Pixel-y14Y.ttf", fontsize=10)

1 Answers1

2

You must run the code in the application loop not in the event loop. The event loop only is executed when there is an event in the queue. The application loop is executed in every frame.

# applicaition loop
run = True
while run:

    # event loop
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

        # handle the events here
        # this code is executed once for each event
        # [...]

    # update the objects and draw the scene here
    # this code is executed once per frame
    # [...]

See also Why is my PyGame application not running at all?.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174