Using display.flip is slower since it updates all the screen. display.update updates only the area covered by the list of "dirty" rectangles.
2014-06-12 15:49 GMT+02:00 Christopher Night <cosmologi...@gmail.com>: > I get that you want to understand what's going on, but beyond that, is > there some problem with just using display.flip? > > > On Thu, Jun 12, 2014 at 3:31 AM, Abhas Bhattacharya < > abhasbhattachar...@gmail.com> wrote: > >> The following code draws a circle and moves it by 4px to left every step. >> >> Problem is that at about 60 fps or more, the circle flickers and >> sometimes looks cut off to me (approx. illustration - >> http://i.imgur.com/4nKzsCP.png). The flickering is not like a screen >> flicker, more like state switching between full circle and cut-off circle. >> This problems doesnt occur at all upto 45 fps, couldnt be reproduced by >> screen capture or pausing the game, as if the problem is only visible to >> the naked eye. >> >> Now, there could be two possibilities: >> >> * Screen is not updated over the required region. >> >> None of the update code depends on the fps, so the flicker should have >> been fps-independent. But, the problem disappears at 30/45 fps. But, >> surprisingly, it is also fixed if display.flip is used instead of update. >> >> * V-sync/monitor refresh problem >> >> Some other pygame flicker questions mentioned this problem. I thought >> software rendering doesnt have this problem, but not really sure. Also, why >> would display.flip fix this? >> >> Ver- 1.9.2 a0 >> >> import pygame >> w,h=800,200 >> fps=60 >> pygame.init() >> screen = pygame.display.set_mode([w, h]) >> color=pygame.Color("white") >> clock=pygame.time.Clock() >> radius=20 >> x,y=800,100 >> def get_bbox(x,y): >> left = x - radius >> top = y - radius >> width = radius * 2 >> height = radius * 2 >> return pygame.Rect((left, top), (width, height)) >> >> while True: >> old_x=x >> x-=4 >> screen.fill(pygame.Color("black"),get_bbox(old_x,y)) >> pygame.draw.circle(screen, color, (x, y), radius, 1) >> pygame.display.update([get_bbox(x,y),get_bbox(old_x,y)]) >> clock.tick(fps) >> > >