Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between pygame.display.update and pygame.display.flip

Just like the title implies, is there any difference? I was using pygame.display.flip and I saw on the Internet that instead of using flip they used pygame.display.update. Which one is faster?

like image 202
Yubin Lee Avatar asked Mar 28 '15 08:03

Yubin Lee


People also ask

What is the difference between pygame display update and pygame display flip?

flip() updates the whole screen. pygame. display. update() updates only specific section but with no arguments works similar to the pygame.

What is pygame display update?

Pygame has a single display Surface that is either contained in a window or runs full screen. Once you create the display you treat it as a regular Surface. Changes are not immediately visible onscreen; you must choose one of the two flipping functions to update the actual display.

How do you flip the screen on pygame?

To flip the image we need to use pygame. transform. flip(Surface, xbool, ybool) method which is called to flip the image in vertical direction or horizontal direction according to our needs.

What is pygame display Set_mode?

display is a module, and set_mode is a function inside that module. It actually creates an instance of the pygame. Surface class, and returns that. See the docs. In Python, the standard is that classes have capitalised names, and modules and functions are all lower case.


1 Answers

The main difference between pygame.display.flip and pygame.display.update is, that

  • display.flip() will update the contents of the entire display
  • display.update() allows to update a portion of the screen, instead of the entire area of the screen. Passing no arguments, updates the entire display

To tell PyGame which portions of the screen it should update (i.e. draw on your monitor) you can pass a single pygame.Rect object, or a sequence of them to the display.update() function. A Rect in PyGame stores a width and a height as well as a x- and y-coordinate for the position.

PyGame's built-in dawning functions and the .blit() method for instance return a Rect, so you can simply pass it to the display.update() function in order to update only the "new" drawn area.

Due to the fact that display.update() only updates certain portions of the whole screen in comparison to display.flip(), display.update() is faster in most cases.

like image 119
elegent Avatar answered Oct 11 '22 14:10

elegent