Why You Should be Excited About PyGame 2

by Neil Muller

PyCon ZA 2022

What is PyGame

Quoting PyPI page:

pygame is a free and open-source cross-platform library for the development of multimedia applications like video games using Python. It uses the Simple DirectMedia Layer library and several other popular libraries to abstract the most common functions, making writing these programs a more intuitive task.
a
  • Heavily focused on 2D games
  • Providex expected graphics, audio & input helpers require
  • A somewhat "fat" wrapper around SDL - uses SDL for the basic opeations, but provides significant functionality that is not part of the SDL libraries (sprite support, math routines, etc)

PyGame Releases

  • PyGame 0.1 - October 2000 (first public release)
  • PyGame 1.0 - April 2001
  • PyGame 1.7.1 - August 2005
  • PyGame 1.9 - August 2009
  • PyGame 1.9.6 - April 2019
  • PyGame 2.0 - October 2020
  • PyGame 2.1.0 - Nov 2021

So why did PyGame 2 take so long?

Simple DirectMedia Layer

SDL 1.2 (first released in 2000)

  • Provides cross-platform support for audio, video, file i/o, video, etc.
  • Designed around the idea of full-screen, single window games - minimal windowing support
  • Video build around the idea of Surfaces - 2d pixel buffers that could be manipulated
  • Optimized for area-based blit/update operations - per-pixel drawing operations possible, but slow
  • Surfaces could be used with OpenGL, but SDL used no OpenGL operations, just a way to pass surfaces to OpenGL code

SDL 2.0 (first release in 2013)

Many improvements and changes - see https://wiki.libsdl.org/MigrationGuide#overview_of_new_features

Some significant ones

  • More support for "modern" GPU features
  • API is still based around 2D operations, but allows more use of GPU operations for faster processing
  • Rewritten to support multiple windows / displays
  • Various additions / reworks of the imput system - proper unicode input, multi-touch support, etc
  • Mobile platforms became first-class citizens of the ecosystem

Did not attempt to maintain backwards compatibility with SDL 1.2

PyGame & SDL 2

  • Extensive work needed to support SDL 2 changes
  • "fat" wrapper approach meant changes more far-reaching than many anticipated
  • Desire to keep backwards compatability also added complications

So what new shinies are there?

  • SCALED mode
  • Significant improvements to PyPy support - further improvements actively being worked on
  • Android support as first class targer
  • Better support for pinstaller & cx_Freeze
  • Various other fixes
  • Support for SDL 2 and related features (touch support, multiple windows, etc)
  • Type Hints

Demos

Watch closely

Support for SDL 2 features

  • Generally works well
  • Still a fairly direct wrapper around SDL2 structures
  • API is still very much a work in progress

Type Hints

  • Type hints for all PyGame functions
  • Generally works as expected
  • Sometime more restrictive than PyGame itself - specifies pygame.Color where PyGame will accept a tuple or string