Search results
Results from the WOW.Com Content Network
Once you've got pygame installed (pip install pygame or pip3 install pygame for most people), the next question is how to get a game loop running. Pygame, unlike some other libraries, gives you full control of program execution.
The pygame package represents the top-level package for others to use. Pygame itself is broken into many submodules, but this does not affect programs that use pygame. As a convenience, most of the top-level variables in pygame have been placed inside a module named pygame.locals pygame constants.
Many sequential drawing calls can be sped up by locking and unlocking the surface object around the draw calls (see pygame.Surface.lock() lock the Surface memory for pixel access and pygame.Surface.unlock() unlock the Surface memory from pixel access).
The pygame website has full reference documentation for every pygame function and tutorials for all ranges of users. The pygame source comes with many examples of things like monkey punching and UFO shooting.
Pygame requires Python; if you don't already have it, you can download it from python.org. It's recommended to run the latest python version, because it's usually faster and has better features than the older ones.
Use the functions pygame.display.mode_ok(), pygame.display.list_modes(), and pygame.display.Info() to query detailed information about the display. Once the display Surface is created, the functions from this module affect the single existing display.
To keep pygame in sync with the system, you will need to call pygame.event.pump() internally process pygame event handlers to keep everything current. Usually, this should be called once per game loop.
David Clark is an avid pygame user and the editor of the Pygame Code Repository, a showcase for community-submitted python game code. He is also the author of Twitch, an entirely average pygame arcade game. This guide was substantially updated in 2022.
By the end of the tutorial, you should not only have a firmer grasp of pygame, but you should also understand how TomPong works, and how to make your own version. Now, for a brief recap of the basics of pygame.
On older pygame versions, MP3 support was limited under Mac and Linux. This changed in pygame v2.0.2 which got improved MP3 support. Consider using OGG file format for music as that can give slightly better compression than MP3 in most cases.