Skip to content

Instantly share code, notes, and snippets.

@iKlsR
Last active July 25, 2018 23:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save iKlsR/3252374 to your computer and use it in GitHub Desktop.
Save iKlsR/3252374 to your computer and use it in GitHub Desktop.
pygame boilerplate..
import pygame
import os, sys
width, height = 400, 400
os.environ['SDL_VIDEO_CENTERED'] = '1'
screen = pygame.display.set_mode((width, height))
class Core(object):
def __init__(self, surface, name):
pygame.display.set_caption(name)
self.screen = surface
def dispatch(self, event):
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
pass
def run(self):
while True:
for event in pygame.event.get():
self.dispatch(event)
self.screen.fill([0xFF, 0xFF, 0xFF])
pygame.display.flip()
if __name__ == '__main__':
main = Core(screen, 'Node')
main.run()
@nchudleigh
Copy link

Awesome!

@Rumidom
Copy link

Rumidom commented Jul 25, 2018

an better way to quit pygame is to use pygame.quit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment