How to capture pygame screen?

2019-02-12 10:17发布

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()

1条回答
来,给爷笑一个
2楼-- · 2019-02-12 10:35

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.

查看更多
登录 后发表回答