title: Why is the sprite image not resetting to default when I'm not pressing anything in this pygame script?
body: <pre><code>import pygame
  from config import *
  from spritesheet import *
  import math
  
  class Player(pygame.sprite.Sprite):
      def __init__(self, game, x, y):
  
          self.game = game
          self._layer = PLAYER_LAYER
          self.groups = self.game.all_sprites
          pygame.sprite.Sprite.__init__(self, self.groups)
  
          self.x = x * TILESIZE2
          self.y = y * TILESIZE2
          self.width = PLAYERSIZEX
          self.height = PLAYERSIZEY
  
          self.x_change = 0
          self.y_change = 0
  
          self.facing = 'right'
          self.animation_loop = 0
      
          self.allowed_to_animate = 1
  
  
          self.image = self.game.mario.get_sprite(0, 8, self.width, self.height)
  
          self.image = pygame.transform.scale(self.image, (TILESIZE2, TILESIZE2))
  
          self.rect = self.image.get_rect()
          self.rect.x = self.x
          self.rect.y = self.y
      
          self.vel_y = 0
          self.jump = False
          self.inAir = False
  
  
      def update(self):
          self.movement()
          self.animate()
  
          self.rect.x += self.x_change
          self.collide_blocks('x')
          self.rect.y += self.vel_y
          self.collide_blocks('y')
      
          if self.facing == &quot;right&quot;:
              self.game.mario.get_sprite(0, 8, self.width, self.height)
  
          self.x_change = 0
          self.image = pygame.transform.scale(self.image, (TILESIZE2, TILESIZE2))
  
      def movement(self):
          keys = pygame.key.get_pressed()
          if keys[pygame.K_LEFT]:
              for sprite in self.game.all_sprites:
                  sprite.rect.x += PLAYER_SPEED
              self.x_change -= PLAYER_SPEED
              self.facing = &quot;left&quot;
    
          if keys[pygame.K_RIGHT]:
                  for sprite in self.game.all_sprites:
                  sprite.rect.x -= PLAYER_SPEED
              self.x_change += PLAYER_SPEED
              self.facing = &quot;right&quot;
              
          if keys[pygame.K_z] and self.jump == False and self.inAir == False:
              self.vel_y = -15
              self.jump = True
              self.inAir = True
          
          if keys[pygame.K_z] == False:
              self.jump = False
          
          self.vel_y += 1
          
          if self.vel_y &gt; 10:
              self.vel_y = 10
   
  
      def collide_blocks(self, direction):
          if direction == &quot;x&quot;:
              hits = pygame.sprite.spritecollide(self, self.game.blocks, False)
              if hits:
                  if self.x_change &gt; 0:
                      self.rect.x = hits[0].rect.left - self.rect.width
                      for sprite in self.game.all_sprites:
                          sprite.rect.x += PLAYER_SPEED
                  if self.x_change &lt; 0:
                      self.rect.x = hits[0].rect.right
                      for sprite in self.game.all_sprites:
                          sprite.rect.x -= PLAYER_SPEED
  
              if direction == &quot;y&quot;:
              hits = pygame.sprite.spritecollide(self, self.game.blocks, False)
              if hits:
                  if self.vel_y &gt; 0:
                      self.rect.y = hits[0].rect.top - self.rect.height
                      self.inAir = False
                
                  if self.vel_y &lt; 0:
                      self.rect.y = hits[0].rect.bottom                     
                      self.inAir = False
  
      def animate(self):
          run_anim_right = [self.game.mario.get_sprite(20, 8, self.width, self.height),
                      self.game.mario.get_sprite(38, 8, self.width, self.height),
                      self.game.mario.get_sprite(56, 8, self.width, self.height),]
  
          run_anim_left = [self.game.mario.get_sprite(76, 25, self.width, self.height),
                      self.game.mario.get_sprite(58, 25, self.width, self.height),
                      self.game.mario.get_sprite(40, 25, self.width, self.height),]
                  
          jump_right = self.game.mario.get_sprite(96, 8, self.width, self.height)
          jump_left = self.game.mario.get_sprite(0, 25, self.width, self.height)
  
          if self.facing == &quot;right&quot;:
              if self.inAir == False:
                  if self.x_change == 0:
                      self.animation_loop = 0
                      self.game.mario.get_sprite(0, 8, self.width, self.height)
                      self.image = pygame.transform.scale(self.image, (TILESIZE2, TILESIZE2))
  
                  else:
                      self.image = run_anim_right[math.floor(self.animation_loop)]
                      self.animation_loop += 0.1
                      if self.animation_loop &gt;= 3:
                          self.animation_loop = 0
                      
              else:
                  self.image = jump_right
  
          if self.facing == &quot;left&quot;:
              if self.inAir == False:
                  if self.x_change == 0:
                      self.animation_loop = 0
                      self.game.mario.get_sprite(96, 25, self.width, self.height)
                      self.image = pygame.transform.scale(self.image, (TILESIZE2, TILESIZE2))
  
                  else:
                      self.image = run_anim_left[math.floor(self.animation_loop)]
                      self.animation_loop += 0.1
                      if self.animation_loop &gt;= 3:
                          self.animation_loop = 0
                  
              else:
                  self.image = jump_left
  </code></pre>
  <p>I've tried and tried again to set the image to default <code>(self.game.mario.get_sprite(0, 8, self.width, self.height)</code> but nothing I seem to do works. I've tried adding everything, from trying to make the x speed to 0 (didnt work), and like, everything. Since you guys can somehow figure this stuff out, and I really need help</p>
  <p>(full program here: <a href="https://replit.com/@PikadaveStudios/Mario-Creepypasta-Game?v=1" rel="nofollow noreferrer">https://replit.com/@PikadaveStudios/Mario-Creepypasta-Game?v=1</a>)</p>