Sunday, November 25, 2012

Walking Animation with Pygame

My son spent an hour going through a great video from the Films by Kris site.  The video PyGame - Sprite Animation Walk Loop is a great introduction to walking animation and quite rewarding.  My son was able to create the application above in under an hour.

Although the original video has the character walking backward, my son changed the orientation of the character with the pygame.transform.flip method.

It's a fairly minor change.

        if self.direction == "right":
            windowSurface.blit(self.img, (self.x, self.y))
        elif self.direction == "left":
            self.left_img = pygame.transform.flip(self.img, True, False)  
            windowSurface.blit(self.left_img, (self.x, self.y))

More information on Pygame surface transformation is available here.

The tutorial that Films by Kris used is embedded below.

No comments:

Post a Comment