Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture pygame screen?

How can I capture and save a sequence of images or a video of a pygame screen?
Basically I want to share my game video on youtube. Also, want to make a tutorial.

The game is rendered mainly in a loop:

def main():
    while True:
        GetInput()
        Move()
        Shift()
        Draw()

With the Draw() function doing all the blit() and stuff before doing the pygame.display.flip()

like image 699
lalli Avatar asked May 22 '11 11:05

lalli


1 Answers

Use pygame.image.save on your screen surface:

window = pygame.display.set_mode(...)

...

pygame.image.save(window, "screenshot.jpeg")

Note that this will slow down your program tremendously. If it is time-based, you may wish to fake the framerate when doing a capture.

like image 181
sam hocevar Avatar answered Sep 28 '22 16:09

sam hocevar