Last active
July 4, 2016 08:31
-
-
Save seanmtracey/1d81c496932710c2113d4e1c3c332ff6 to your computer and use it in GitHub Desktop.
A snippet that enables Pygame Zero games to take screenshots during gameplay and save them to a 'screenshots' directory in the same path.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pygame import image as PGI | |
import time | |
def take_screenshot(Surface): | |
outputDir = './screenshots/' | |
if not os.path.exists(outputDir): | |
os.makedirs(outputDir) | |
PGI.save(Surface, outputDir + str( int(time.time()) ) + '.png' ) | |
def on_key_down(key): | |
if key == keys.P: | |
take_screenshot(screen.surface) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment