Uploaded February 2013 | Updated November 2026, 3 hours ago
In this video I show you how to animate your images. I also show you how to use the clock object to limit the frame rate so the animation is smooth. This is very useful in creating good quality games. Please like the video if you enjoyed! Also please subscribe.
Mario Sprite Sheet (for the mario images):
http://3.bp.blogspot.com/-haGIpD8HV70/UI8b6626YTI/AAAAAAAABuY/nOzTRM7TNdc/s1600/mario33.png
Download this project (with the images):
dropbox.com/s/yo18m55f3ztwg5o/pygameanimation.zip
Code:
import pygame
pygame.init()
window = pygame.display.set_mode((800,600))
pygame.display.set_caption("Animation")
white = (255,255,255)
clock = pygame.time.Clock()
# Mario sprites
m1 = pygame.image.load("images/m1.png")
m2 = pygame.image.load("images/m2.png")
marioCurrentImage = 1
gameLoop=True
while gameLoop:
for event in pygame.event.get():
if (event.type==pygame.QUIT):
gameLoop=False
window.fill(white)
if (marioCurrentImage==1):
window.blit(m1, (10,10))
if (marioCurrentImage==2):
window.blit(m2, (10,10))
if (marioCurrentImage==2):
marioCurrentImage=1
else:
marioCurrentImage+=1;
pygame.display.flip()
clock.tick(10)
pygame.quit()
In this video I show you how to animate your images. I also show you how to use the clock object to limit the frame rate so the animation is smooth. This is very useful in creating good quality games. Please like the video if you enjoyed! Also please subscribe.
Mario Sprite Sheet (for the mario images):
http://3.bp.blogspot.com/-haGIpD8HV70/UI8b6626YTI/AAAAAAAABuY/nOzTRM7TNdc/s1600/mario33.png
Download this project (with the images):
dropbox.com/s/yo18m55f3ztwg5o/pygameanimation.zip
Code:
import pygame
pygame.init()
window = pygame.display.set_mode((800,600))
pygame.display.set_caption("Animation")
white = (255,255,255)
clock = pygame.time.Clock()
# Mario sprites
m1 = pygame.image.load("images/m1.png")
m2 = pygame.image.load("images/m2.png")
marioCurrentImage = 1
gameLoop=True
while gameLoop:
for event in pygame.event.get():
if (event.type==pygame.QUIT):
gameLoop=False
window.fill(white)
if (marioCurrentImage==1):
window.blit(m1, (10,10))
if (marioCurrentImage==2):
window.blit(m2, (10,10))
if (marioCurrentImage==2):
marioCurrentImage=1
else:
marioCurrentImage+=1;
pygame.display.flip()
clock.tick(10)
pygame.quit()








