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.
In the data folder, you will find a spritesheet2) from Ari Feldmann's Spritelib ( http://www.widgetworx.com/spritelib/ ) 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.
Source Code on Github
To run this example you need:
|008_animation.py|| || Download the whole Archive with all files from Github:
| char9.bmp ||
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: