python - Pygame, screen only updates when exiting pygame window? -


i'm new pygame , needed because code not working properly.

okay here's problem: want screen turn white when run remains black, when press exit, turns white second , closes.

this happens when put picture (like player.png) appears second before exiting. don't know i'm doing wrong,

please fix code , explain why happening?

here code:

import pygame  pygame.init()  screen = pygame.display.set_mode((640,480)) image = pygame.image.load('player.png') gameexit = false gameloop = true  pygame.display.update() white = (255,255,255)  while not gameexit:     event in pygame.event.get():         if event.type == pygame.quit:         gameexit = true      event in pygame.event.get():         screen.fill(white)        pygame.display.update()     pygame.quit() quit() 

ps. don't errors

python indentation sensitive. in code, call pygame.display.update() once main loop ends.

also, paint background white in case there's event in event queue between 2 for loops, , fill background every event in queue.

note lead situation in quit event "swallowed" second loop.


so this

while not gameexit:     event in pygame.event.get():         if event.type == pygame.quit:         gameexit = true      event in pygame.event.get():         screen.fill(white)  pygame.display.update() 

should be

while not gameexit:     event in pygame.event.get():         if event.type == pygame.quit:             gameexit = true      screen.fill(white)      pygame.display.update() 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -