0
    # Move the player.
    if moveDown and player.bottom < WINDOWHEIGHT:
        player.top += MOVESPEED
        playerImage = pygame.image.load('PlayerFSprite1.png')
        playerStretchedImage = pygame.transform.scale(playerImage, (256, 256))
        windowSurface.blit(playerStretchedImage, player)

    if moveUp and player.top > 0:
        player.top -= MOVESPEED
        playerImage = pygame.image.load('Player USprite.png')
        playerStretchedImage = pygame.transform.scale(playerImage, (256, 256))
        windowSurface.blit(playerStretchedImage, player)

    if moveLeft and player.left > 0:
        player.left -= MOVESPEED
        playerImage = pygame.image.load('PlayerLSprite.png')
        playerStretchedImage = pygame.transform.scale(playerImage, (256, 256))
        windowSurface.blit(playerStretchedImage, player)

    if moveRight and player.right < WINDOWWIDTH:
        player.right += MOVESPEED
        playerImage = pygame.image.load('PlayerRSprite.png')
        playerStretchedImage = pygame.transform.scale(playerImage, (256, 256))
        windowSurface.blit(playerStretchedImage, player)

This code is making a sprite move a direction with a certain animation but I was wondering how I can make the animation switch to another animation while holding down the key direction so when holding "W" there will be the first animation and then after a 0.2 second delay another animation appears.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Helpmeplx
  • 1
  • 3
  • I'm not sure what you intend to do. Please elaborate the question. Maybe [this answer](https://stackoverflow.com/a/48161016/6220679) might be helpful to you. – skrx Jan 10 '18 at 04:39
  • you have to keep animation's frames on list and use variable `current_frame` to blit correct frame from list. You have to use `pygame.time.Clock()` to control time and change `current_frame` every 0.2s (in pygame it will be 200ms) – furas Jan 10 '18 at 08:37
  • better load and transform images only once - at start - because loading take a lot time. Or even transform images on Photoshop/Gimp/etc and load image with corect size. With Photoshop/Gimp you can better transform images. – furas Jan 10 '18 at 08:40
  • see example [animation with spritesheet](https://github.com/furas/python-examples/tree/master/pygame/spritesheet) – furas Jan 10 '18 at 08:42
  • You do not mention it, but we are all assuming you mean, w is moveUp, and the player's movement is not the animation that you are trying to achieve after a delay, is that right? – nycynik Jan 10 '18 at 15:09
  • Yes you are correct about that @nycynik – Helpmeplx Jan 10 '18 at 18:25
  • @furas can you please elaborate on how to use current_frame with the animation – Helpmeplx Jan 10 '18 at 18:36
  • see example in previous comment - it uses list with images and `current_frame` to get image from list and display it - and after that it increases `current_frame += 1` to display next frame/image in next loop. – furas Jan 11 '18 at 11:28

0 Answers0