0

I do not understand what the difference is between pygame.display.update() and pygame.display.flip().

I have tried both and it seems that update() is slower than flip()...

EDIT:

My question is why update() with no parameters is much slower than flip().

Thanks!

Micheal O'Dwyer
  • 1,237
  • 1
  • 16
  • 26
Bob5421
  • 7,757
  • 14
  • 81
  • 175

1 Answers1

6

You must first understand how pygame.display.flip and pygame.display.update work.

When the screen mode pygame.DOUBLEBUF is set, Pygame actually maintains two screens: the active screen which is presently displayed and a buffer which you (the programmer) can update behind the scenes (without the user seeing anything).

Once you are done with your edits on the buffer, you can use pygame.display.flip to switch the active screen with the buffer. The entire screen is updated. This is the recommended way to update the entire screen. Also, this is the only way to update non-software screens (OPENGL and Hardware accelerated screens for example).

pygame.display.update on the other hand treats the screen as a group of pixels (that's called a software screen). This allows a Pygame program to update only a portion of the screen. This is faster as only a portion of the screen needs to be modified.

Now, if the entire screen is to be updated (pygame.display.flip and pygame.display.update without any arguments) pygame.display.flip is faster.

Remember, I said OpenGL and HW-accelerated screens (SOFT-screens too) maintain a buffer. Drawing to this buffer is slow, but flipping is very fast (in HW-screens and OpenGL). Updating the entire screen using pygame.display.update is even slower as it does things pixel by pixel and without HW-acceleration.

Abhishek Kumar
  • 461
  • 2
  • 11
  • Hi, thanks for your answer! You said:" if the entire screen is to be updated (pygame.display.flip and pygame.display.update without any arguments) pygame.display.flip is faster." Does the situation is still under `DOUBLEBUF` mode, or any mode flip is faster than update to update the entire screen? – roachsinai Apr 07 '20 at 15:15