Skip to content

Instantly share code, notes, and snippets.

@shorinji
Created June 26, 2020 20:51
Show Gist options
  • Save shorinji/4e37a1cb1ec049a4cd4486dafb9fa30e to your computer and use it in GitHub Desktop.
Save shorinji/4e37a1cb1ec049a4cd4486dafb9fa30e to your computer and use it in GitHub Desktop.
example snippet of building up filenames and loading images dynamically
walkRightImageCodes = ['A1', 'A2', 'A7', 'Fb9', 'Bx5']
walkRightImageData = []
# easy to read version
for code in walkRightImageCodes:
filename = "%s.png" % code
imageData = pygame.image.load(filename).convert()
walkRightImageData.append(imageData)
# short version
walkRightImageData = [ pygame.image.load("%s.png" % code).convert() for code in imageCodes ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment