The sprite's "costume" is the image that's drawn on the screen for it. First, think about when you want the sprite's costume to change: -- Continuously changing on it's own? -- It changes only when the player clicks on it? Does it change back when the player clicks on it again? Do costumes change in a sequence? -- It changes based on which direction the player is moving the sprite with the arrow keys (left, right, up, or down)? -- Do you need to be able to reset it to have the original costume? SPRITE COSTUME CHANGES CONTINUOUSLY: Your sprite class should already have an update function that determines how the sprite moves. For example, if your sprite bounces around the screen without user input, the update function might look like: def update(self): self.rect = self.rect.move(self.speed) if self.rect.left < 0 or self.rect.right > self.windowwidth: self.speed[0] = -self.speed[0] if self.rect.top < 0 or self.rect.bottom > self.windowheight: self.speed[1] = -self.speed[1] The update function should also be called regularly on the sprite in the main while loop. For example: player.update() In your Player sprite class, change 'def __init__(self, image_file, center_location):' to 'def __init__(self, image_list, center_location):'. In the __init__ function, add the following lines before you set up the sprite's image. self.image_list = image_list self.frame = 0 Then, change 'self.image,self.rect = load_image(image_file, -1)' to 'self.image,self.rect = load_image(image_list[self.frame], -1)'. Find the line where you initialize your player object (for example, 'player = Player("player.png",(windowwidth/2,windowheight/2))'). Change the image file to a list of image files in the order you want them to rotate. For example: player = Player(["player1.png","player2.png","player3.png"],(windowwidth/2,windowheight/2)). If your sprite is in a group, this will look like: playersprites.add(Player(["player1.png","player2.png","player3.png"],(windowwidth/2,windowheight/2))). Try running the program, and your player sprite should stay as the first image in the list. Add the following line to the Player sprite class __init__ function: self.animation_cycle = 10 # the higher the number, the slower the rotation will be Later, you can play with the speed of the animation by changing this number. Add the following lines to the Player sprite class update function: self.frame = self.frame + 1 center_location = self.rect.center self.image,self.rect = load_image(self.image_list[self.frame/self.animation_cycle%len(self.image_list)],-1) self.rect.center = center_location CHANGE COSTUMES IN A SEQUENCE WITH MOUSE CLICK: The sprite costume will run through a sequence of images every time the mouse clicks on it. In your Player sprite class, change 'def __init__(self, image_file, center_location):' to 'def __init__(self, imagefile, animation_image_list,center_location):'. In the __init__ function, add the following lines before you set up the sprite's image. self.animation_image_list = animation_image_list self.animation_frame = 0 self.animation_sequence = False self.animation_cycle = 100 Find the line where you initialize your player object (for example, 'player = Player("player.png",(windowwidth/2,windowheight/2))'). Add a list of the images to run through in the costume change sequence. For example: player = Player("player.png",["player1.png","player2.png","player3.png"],(windowwidth/2,windowheight/2)). If your sprite is in a group, this will look like: playersprites.add(Player("player.png",["player1.png","player2.png","player3.png"],(windowwidth/2,windowheight/2))). Create a function in your sprite class that will be called when the mouse clicks on the sprite: def on_click(self): self.animation_sequence = True Add the following to the update function in your sprite class: if self.animation_sequence: self.animation_frame = self.animation_frame + 1 if self.animation_frame/self.animation_cycle < len(self.animation_image_list): center_location = self.rect.center self.image,self.rect = load_image(self.animation_image_list[self.animation_frame/self.animation_cycle],-1) self.rect.center = center_location else: self.animation_frame = 0 self.animation_sequence = False Note that the sprite will remain as the last image in the animation sequence list. Add the following to the event checking section in the main while loop: elif event.type == pygame.MOUSEBUTTONDOWN: if player.rect.collidepoint(event.pos): player.on_click() If your sprite is in a group, this will look like: elif event.type == pygame.MOUSEBUTTONDOWN: for player in playersprites: if player.rect.collidepoint(event.pos): player.on_click() Make sure you update the player ('player.update()') every time the while loop runs. If you control your sprite with the arrow keys (in which case, the update function gets called only when the arrow keys are pressed), add 'player.update(None)' before 'screen.blit(background,(0,0))'. CHANGE THE SPRITE COSTUME WITH MOUSE CLICK (COSTUME DOES NOT CHANGE BACK): In your Player sprite class, change 'def __init__(self, image_file, center_location):' to 'def __init__(self, image_list, center_location):'. In the __init__ function, add the line 'self.image_list = image_list' before setting up the sprite's image. Then, change 'self.image,self.rect = load_image(image_file, -1)' to 'self.image,self.rect = load_image(image_list[0], -1)'. Find the line where you initialize your player object (for example, 'player = Player("player.png",(windowwidth/2,windowheight/2))'). Change the image file to a list of image files in the order of [first-image, image-after-click]. For example: player = Player(["player.png","player-clicked.png"],(windowwidth/2,windowheight/2)). If your sprite is in a group, this will look like: playersprites.add(Player(["player.png","player-clicked.png"],(windowwidth/2,windowheight/2))). Try running the program, and your player sprite should stay as the first image in the list. Create a function in your sprite class that will be called when the mouse clicks on the sprite: def on_click(self): center_location = self.rect.center self.image,self.rect = load_image(self.image_list[1], -1) self.rect.center = center_location Add the following to the event checking section in the main while loop: elif event.type == pygame.MOUSEBUTTONDOWN: if player.rect.collidepoint(event.pos): player.on_click() If your sprite is in a group, this will look like: elif event.type == pygame.MOUSEBUTTONDOWN: for player in playersprites: if player.rect.collidepoint(event.pos): player.on_click() CHANGE THE SPRITE COSTUME WITH MOUSE CLICK (COSTUME CHANGES ON EVERY CLICK): The sprite costume will rotate through a list of images every time the mouse clicks on it. In your Player sprite class, change 'def __init__(self, image_file, center_location):' to 'def __init__(self, image_list, center_location):'. In the __init__ function, add the following lines before you set up the sprite's image. self.image_list = image_list self.frame = 0 Then, change 'self.image,self.rect = load_image(image_file, -1)' to 'self.image,self.rect = load_image(image_list[self.frame], -1)'. Find the line where you initialize your player object (for example, 'player = Player("player.png",(windowwidth/2,windowheight/2))'). Change the image file to a list of image files in the order you want them to rotate. For example: player = Player(["player1.png","player2.png","player3.png"],(windowwidth/2,windowheight/2)). If your sprite is in a group, this will look like: playersprites.add(Player(["player1.png","player2.png","player3.png"],(windowwidth/2,windowheight/2))). Try running the program, and your player sprite should stay as the first image in the list. Create a function in your sprite class that will be called when the mouse clicks on the sprite: def on_click(self): center_location = self.rect.center self.frame = (self.frame + 1) % len(self.image_list) self.image,self.rect = load_image(self.image_list[self.frame], -1) self.rect.center = center_location Add the following to the event checking section in the main while loop: elif event.type == pygame.MOUSEBUTTONDOWN: if player.rect.collidepoint(event.pos): player.on_click() If your sprite is in a group, this will look like: elif event.type == pygame.MOUSEBUTTONDOWN: for player in playersprites: if player.rect.collidepoint(event.pos): player.on_click() CHANGE THE SPRITE COSTUME WITH ARROW KEYS: Your sprite should already use the arrow key recipe (see sprite-arrow-key-move.txt). In your Player sprite class, change 'def __init__(self, image_file, center_location):' to 'def __init__(self, image_list, center_location):'. In the __init__ function, add the line 'self.image_list = image_list' before setting up the sprite's image. Then, change 'self.image,self.rect = load_image(image_file, -1)' to 'self.image,self.rect = load_image(image_list[0], -1)'. Find the line where you initialize your player object (for example, 'player = Player("player.png",(windowwidth/2,windowheight/2))'). Change the image file to a list of image files for each direction the player will move in the order of [right, left, up, down]. For example: player = Player(["player-right.png","player-left.png","player-up.png","player-down.png"],(windowwidth/2,windowheight/2)). Try running the program, and your player sprite should stay as the first image in the list (the right direction). Go back to the Player sprite class and change your update function to look like the following code: def update(self,key): xMove,yMove = 0,0 center_location = self.rect.center # Determine how much the sprite should move based on the key press if (key == K_RIGHT): xMove += self.x_dist self.image,self.rect = load_image(self.image_list[0], -1) elif (key == K_LEFT): xMove += -self.x_dist self.image,self.rect = load_image(self.image_list[1], -1) elif (key == K_UP): yMove += -self.y_dist self.image,self.rect = load_image(self.image_list[2], -1) elif (key == K_DOWN): yMove += self.y_dist self.image,self.rect = load_image(self.image_list[3], -1) self.rect.center = center_location # Make sure the sprite won't go off the screen (defined by self.area). If it won't, move the sprite if (self.rect.left + xMove >= self.area.left and self.rect.right + xMove <= self.area.right and self.rect.top + yMove >= self.area.top and self.rect.bottom + yMove <= self.area.bottom): self.rect.move_ip(xMove,yMove) RESET TO THE ORIGINAL COSTUME: If you have completed one of the sections above on a sprite class, you can add a function to reset the costume to the original image. Add a function to your sprite class: def reset(self): center_location = self.rect.center self.image,self.rect = load_image(self.image_list[0], -1) self.rect.center = center_location If your sprite class has self.frame (which you may have added during one of the sections above), add the following line to the new reset function: self.frame = 0 To call the reset function in the main while loop, use player.reset(). To reset all the sprites in a group, use: for player in playersprites: player.reset()