Animating sprites
This tutorial will show you how to animate sprites in Pygame. Download and open the file below.
animation.py.zip | |
File Size: | 1 kb |
File Type: | zip |
Tasks
1. What happens if you comment out the following code? Why?
GameWindow.fill(DARKGREEN)
2. The sprite goes off the window on the right boundary, but not on the left. Why is this? Can you stop this from happening?
3. Can you change it so the sprite moves on the y axis as well as the x axis?
4. Change the speed of the sprite movement to be random. Use the following code:
lowestSpeed = 1
highestSpeed = 5
random.randint(lowestSpeed, highestSpeed)
5. Where else could you use randomly generated numbers? Experiment with them.
GameWindow.fill(DARKGREEN)
2. The sprite goes off the window on the right boundary, but not on the left. Why is this? Can you stop this from happening?
3. Can you change it so the sprite moves on the y axis as well as the x axis?
4. Change the speed of the sprite movement to be random. Use the following code:
lowestSpeed = 1
highestSpeed = 5
random.randint(lowestSpeed, highestSpeed)
5. Where else could you use randomly generated numbers? Experiment with them.