Download pyganim.py and example programs. (Works on both Python 2 and 3.)
Details at http://inventwithpython.com/pyganim/
Pyganim is a module that you can import into your Pygame games to handle sprite animation. Creating an animation is simply a matter of supplying a list of image filenames (or pygame.Surface objects) for each frame of animation, along with the duration that each frame lasts. Then call the play() method to start the animation and then call blit() each time you draw the window. The blit() function automatically draws the correct frame based on the amount of real time that has passed since the play() method was called. There are many, many other methods to provide finer levels of control as well.
There is more information available on the Tutorial and Reference page.
I’ve written a book on Python programming for kids and complete beginners. I’ve also done some classroom and one-on-one teaching with adults and teens. I have them use IDLE, the IDE that comes with Python, because it is simple and easier than having them set up some other IDE (like PyDev on Eclipse).
But over time I’ve noticed a lot of problems with IDLE that I wish someone would fix. (I’d like to do it myself but I don’t have the time currently.) I’m very, very grateful that Python comes batteries included vis-à-vis an IDE, but there are a lot of warts and user interface issues with IDLE. (These are different from the bugs listed on the python.org bug tracker.)
First off, my philosophy is that no serious Python programmer uses IDLE as their dev environment. With that assumption, we can get rid of any need to cater to them and make IDLE aimed at people who are not only new to Python but new to programming in general. IDLE should be an education tool more than a development tool. This means that the IDLE default options should all be set for the basic user, not the power user.
With that in mind, these are things I’d like to see changed about the design of IDLE (roughly in order of importance and prior
Here are a couple games I wrote. The first was so popular that I made a sequel:
Win32 EXEs and source:
Look At This Rock
Look At This Rock 2: A Different Rock
Source (requires Pygame to be installed along with Python):
Source: LookAtThisRock.py and PNG
Source: LookAtThisRock2.py and PNG
Here's the introductory chapter to my next book on Python and Pygame. It assumes you have some Python and programming experience (if you don't, give a look to Invent with Python), and offers a quick view of all of the major parts of Pygame.
The chapter by itself is a good introduction to Pygame. If you've been meaning to give Pygame a look, then download the chapter. Please email in any questions or suggestions you have: [email protected]
Unfortunately, the links in the book aren't working yet, but should be in a few days.
Yuanle Qiu has started translating the "Invent Your Own Computer Games with Python" into Chinese. The first
three five chapters are done, with more on the way. Thanks a lot Yuanle!
If you or someone you know can participate in translating "Invent with Python" into other languages (Hindi, Spanish, French, German, etc.) please contact Al for more information. "Invent with Python" is released under a Creative Commons license, so the translated works would be freely available to those who want to learn programming.
If you already know a bit of programming and Python, and want to get up to speed on the Pygame 2D game framework, here's a cheat sheet that you can look over. It implements a very short Pygame program covering most of Pygame's basic features.
View the Pygame Cheat Sheet.
You can also download the Pygame program itself, along with the cat.png and bounce.wav files it uses. You will need to install Python and Pygame first to run this program. The program looks like this when you run it: