Pygame tutorial

Pygame tutorial

Welcome to the Pygame tutorial page. Pygame is a Python module created to make games with python. You can use the pygame 2.0 version with Python 3.8 just installing the dev10 version like this:

pip install pygame==2.0.0.dev10

Pygame is a little bit confusing at first but it is very powerful, completely free and full of examples by the great number of users, so I encorage you to learn it, not only for games but also for guis, presentations, ai etc.

Here I will collect the most interesting posts about my new pygame tutorial that will be costantly updated. This will have an logical sequencial order to make you understand the logic of pygame step by step. Do not forget to bookmark this page and to come back often to see the updates here.

How to install Python

Go here

How to install pygame

How to install Pygame in Python 3.8


  • 1 Window and surfaces
  • 2 Images and background surfaces
  • 3.1 Scaling surfaces

1 – How to make windows and surfaces

The screen surface is the main one onto which you will blit (show) images, sprites and … surfaces. Screen is the main surface and other surfaces will be put onto it to show them, to move them in order to rapresent something or make a game. Let’s soon see how to make a window. Go to the link below to see the video about this themes.

Pygame tutorial n. 1

2 – Images and background

This time we will blit images on the background, together with simple colored surfaces and we will also color the background of the main surface that can be useful to clear the screen during a game.

Pygame tutorial 2 – loading images

3.1 Scaling surfaces

Pygame Tutorial 1 – part 3.1

Bonus part 1: Grab a part of a surface with subsurface

This is about grabbing a part of the screen and I used for Puzzlemania game (the github repo).

Read this good article about pygame sprites.

Pygame Grab part of the screen with subsurface

3.2 – Move the sprite

Finally something’s moving: the sprite. The most simple way to do it is here:

Pygame tutorial 1 – part 3.2 – Move Sprite

3.3 – Animate and move (flip image)

This time the cat will animate. Just the idle position for the moment.

Pygame tutorial 1 – 3.3 – Animation while moving

4. Multiple animation on a single sprite

Here we will try different animations for a single sprite and also a way to modify the speed of the animation. Still a very basic sprite class and no connections with pygame.sprite.Sprite, but that will come soon.

Pygame tutorial 1 – part 4 – More on movement and animations

Bonus part 3: grouping sprites

Pygame tutorial: Group sprites

5. Still on movements and animations

Let’s change the way we moved our sprite in the previous lessons.

Pygame tutorial part. 5


Bonus: rotating image without losing quality


Bonus 5: perfect collisions

Using pygame.sprite.collide_mask(sprite1, sprite2) for collision detection in pygame

Practical examples: making flappy bird

Flappy bird how to make it part 1

Flappy bird how to make it part 1

Flappy bird, how to make it, part II: animation

Flappy bird, how to make it, part II: animation

Flappy tutorial part 3

Flappy tutorial part 3

Flappy Pygame tutorial part 4

Flappy Pygame tutorial part 4 with pygame part 5

Part 5

Pygame Flappy bird tutorial nr. 5 – Sounds and speed

Create a clickable label (or a button) with pygame

Clickable label / button

Pygame clickable Label class: tutorial

Create a map editor and a game that uses the map created