1

I am making a clock in my game. After roughly 60 seconds it changes to the next number. I use the subroutine below to change the clock image when it needs to. My problem is that the images flickers when displayed, and I don't want that.

My code;

def display_night_clock():  
    global var_clock
    global var_6_am
    
    if var_hide == False:
        if var_6_am == False:
            if var_clock == 1:
                screen.blit(image_12_am, (1266, 0))
                pygame.display.update()
            if var_clock == 2:
                screen.blit(image_1_am, (1266, 0))
                pygame.display.update()
            if var_clock == 3:
                screen.blit(image_2_am, (1266, 0))
                pygame.display.update()
            if var_clock == 4:
                screen.blit(image_3_am, (1266, 0))
                pygame.display.update()
            if var_clock == 5:
                screen.blit(image_4_am, (1266, 0))
                pygame.display.update()
            if var_clock == 6:
                screen.blit(image_5_am, (1266, 0))
                pygame.display.update()
            if var_clock == 7:
                screen.blit(image_7_am, (1266, 0))
                pygame.display.update()
                var_6_am = True
                var_clock = 1

I just call this subroutine in my main loop. I have used this method of displaying images before in my program in my other subroutines, and those images don't flicker. But for some reason these images flicker.

Wolfmann Games
  • 142
  • 1
  • 13
  • You're calling `pygame.display.update()` in this method, I suspect you are calling `pygame.display.update()` multiple times per frame/game loop and this is updating the display when you don't want it to? You should only call this once per frame/loop and probably outside of any function other than your main game loop – Iain Shelvington Jun 15 '21 at 03:20

1 Answers1

1

The problem is caused by multiple calls to pygame.display.update(). An update of the display at the end of the application loop is sufficient. Multiple calls to pygame.display.update() or pygame.display.flip() cause flickering.

Remove all calls to pygame.display.update() from your code, but call it once at the end of the application loop:

while running:
   # [...] 

   pygame.display.update()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174