So first of all the code:
import pygame, sys
from pygame.locals import *
class Person(pygame.sprite.Sprite):
def __init__(self, screen):
self.screen = screen
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("images/mariowalking0.png")
self.rect = self.image.get_rect()
self.rect.center = (320, 220)
self.poseNumber = 1
def update(self):
self.rect.centerx += 1
if self.rect.centerx > self.screen.get_width():
self.rect.centerx = 0
self.poseNumber = (self.poseNumber + 1)
if self.poseNumber == 2:
self.poseNumber = 0
self.image = pygame.image.load("images/mariowalking" + str(self.poseNumber) +".png")
def main():
screen = pygame.display.set_mode((640, 480))
background = pygame.Surface(screen.get_size())
background.fill((255, 255, 255))
screen.blit(background, (0, 0))
boy = Person(screen)
allSprites = pygame.sprite.Group(boy)
keepGoing = True
while keepGoing:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keepGoing = False
pygame.quit()
allSprites.clear(screen, background)
allSprites.update()
allSprites.draw(screen)
pygame.display.flip()
if __name__ == "__main__":
main()
If you want to run the code, the images of the sprites can be found here: http://imgur.com/a/FgfAd
The Mario Sprite runs across the screen at a very fast pace. Even though I said that I am going to increase the value of centerx by 1. Any ideas why this is happening.
BTW I am really new to pygame, so sorry if I am overlooking an obvious fact or something.