Translations of this page:

Step 008 - Animation

Remember the Subsurfaces from the last step? And remember that the snake had always the same grinning facial expression? Now, let's make some animated sprites1) - not pygame sprites, but surfaces that show different images of an animation cycle, like a bird flapping its wings.

Instead of painting all the single pictures of an animation cycle myself, I prefer to use ready-made sprite sheets.

In the data folder, you will find a spritesheet2) from Ari Feldmann's Spritelib ( http://www.flyingyogi.com ) showing several pictures of an animal. If you use Ari's sprite's, make sure to include his license information in your program.

With the help of pygame's subsurface command, I will show you how to extract single images from the sprite sheet and use them.

Code Discussion

Source Code on Github

To run this example you need:

file in folder download
008_animation.py pygame Download the whole Archive with all files from Github:
https://github.com/horstjens/ThePythonGameBook/archives/master
char9.bmp
Sprite sheet by Ari Feldman
pygame/data

View/Edit/Download the file directly in Github: https://github.com/horstjens/ThePythonGameBook/blob/master/pygame/008_animation.py

click reload in your browser if you see no code here:

Comment this Page

1) a 2d-object moving around is referred as a Sprite_(computer_graphics)
2) a graphic file with lots of sprites

en/pygame/step008.txt · Last modified: 2014/01/09 11:07 (external edit)