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

前端 未结 2 1672
逝去的感伤
逝去的感伤 2020-11-29 08:24

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

相关标签:
2条回答
  • 2020-11-29 08:41

    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.

    0 讨论(0)
  • 2020-11-29 09:01

    Flip will always update the entire screen. Update also update the entire screen, if you don't give argument. But if you give surface(s) as arguments, it will update only these surfaces. So it can be faster, depending on how many surfaces you give it and their width and height.

    0 讨论(0)
提交回复
热议问题