ThePythonGameBook

learn Python. Create Games

User Tools

Site Tools


en:part2:pygame:step008

This is an old revision of the document!


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 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.

discussion

additional resources

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

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:

1)
a 2d-object moving around is referred as a Sprite_(computer_graphics)
2)
a graphic file with lots of sprites
/var/www/horst/thepythongamebook.com/data/attic/en/part2/pygame/step008.1305269170.txt.gz · Last modified: 2014/01/09 11:07 (external edit)