I have a simple animation to handle where I draw a rectangle and when I click on the surface, the rectangle slid left and wait for 2 seconds and then redraw it with a slid motion to the right, but if I reduce or move the window and make a try the window freezes on the waiting moment.
Here is the code:
import sys, pygame
from pygame.locals import *
pygame.init()
FPS = 30
BGCOLOR = (255, 255, 255)
RECTCOLOR = (10, 0, 199)
DS = pygame.display.set_mode( (200,200) )
CLOCK = pygame.time.Clock()
pygame.display.set_caption('Demo')
def main():
DS.fill(BGCOLOR)
pygame.draw.rect(DS, RECTCOLOR, (50, 50, 100, 100))
pygame.display.update()
while 1:
ev = pygame.event.wait()
if ev.type == QUIT:
pygame.quit()
sys.exit()
elif ev.type == MOUSEBUTTONUP:
animation()
def animation():
pygame.event.set_blocked(MOUSEBUTTONUP)
for x in range(10, 101, 10):
pygame.draw.rect(DS, BGCOLOR, (150 - x,50,x,100))
pygame.display.update()
CLOCK.tick(FPS)
pygame.time.wait(2000) # 2 seconds
for x in range(10, 101, 10):
pygame.draw.rect(DS, RECTCOLOR, (50,50,x,100))
pygame.display.update()
CLOCK.tick(FPS)
pygame.event.set_allowed(MOUSEBUTTONUP)
if __name__ == '__main__':
main()
Why we have this sort of behavior ?, maybe the system don't synchronize between the pause moment and the ticks in the second for loop
PS: i'm on windows 7 and sorry for my english it's not my native language