title: Pygame: converting .png file to rect?
body: <p>I've been working on this small game for a while and I've encountered a headache. Below you can see that "square1" and "square2" are drawn with pygame. I want to replace them with images, but it messes up the colliderect stuff I've done. Is it possible to "convert" a loaded .png image into a rect object?</p>
  
  <pre><code>import pygame
  import os
  
  from test_menu import drawmenu
  from game_over import player1wins
  from game_over import player2wins
  from game_over import tie
  pygame.init()
  
  while True: 
      screen_size = (1080, 400)
      screen = pygame.display.set_mode(screen_size)
  
      background = (255,255,255)
      image = pygame.image.load("background(1).png")
      imagerect = image.get_rect()
      wall_left = pygame.Rect(0,0,1,950)
      wall_right = pygame.Rect(1080,0,1,950)
  
      square1 = pygame.Rect(750, 350, 20, 20)
      square2 = pygame.Rect(330, 350, 20, 20)
  
      x_movement = 0
      y_movement = 0
      x2_movement = 0
      y2_movement = 0
  
      accelx1 = 0
      accely1 = 0
      accelx2 = 0
      accely2 = 0
  
      jumping = False
      jumping2 = False
  
      def health_bars(player1_health, player2_health):
          if player1_health &gt; 75:
              player1_health_color = (62, 219, 41)
          elif player1_health &gt; 50:
              player1_health_color = (239, 212, 9)
          else:
              player1_health_color = (239, 9, 9)
  
          if player2_health &gt; 75:
              player2_health_color = (62, 219, 41)
          elif player2_health &gt; 50:
              player2_health_color = (239, 212, 9)
          else:
              player2_health_color = (239, 9, 9)
  
          pygame.draw.rect(screen, player1_health_color, (70, 50, player1_health, 25))
          pygame.draw.rect(screen, player2_health_color, (900, 50, player2_health, 25))
  
      player1_health = int(100)
      player2_health = int(100)
  
      drawmenu()
  
      while True:
          screen.fill(background)
          screen.blit(image, imagerect)
          pygame.display.update()
          pygame.draw.rect(screen, (255,0,0), square1)
          pygame.draw.rect(screen, (0,0,255), square2)
          pygame.draw.rect(screen, (0,0,0), wall_left)
          pygame.draw.rect(screen, (0,0,0), wall_right)
          health_bars(player1_health, player2_health)
          pygame.display.update()
          events = pygame.event.get()
          for event in events:
              if event.type == pygame.QUIT:
                  exit()
          keys_pressed = pygame.key.get_pressed()
          pygame.time.delay(20)
  
          #MOVEMENT P1
  
          if keys_pressed[pygame.K_LEFT] == 1:
              x_movement += -1
          elif keys_pressed[pygame.K_RIGHT] == 1:
              x_movement += 1
          else:
              x_movement = 0
  
          #MOVEMENT P2
  
          if keys_pressed[pygame.K_a] == 1:
              x2_movement += -1
          elif keys_pressed[pygame.K_d] == 1:
              x2_movement += 1
          else:
              x2_movement = 0
  
          #MAX SPEED P1
          if x_movement &lt; -7:
              x_movement = -7
          if x_movement &gt; 7:
              x_movement = 7
          if y_movement &lt; -7:
              y_movement = -7
          if y_movement &gt; 7:
              y_movement = 7
  
          #MAX SPEED P2
          if x2_movement &lt; -7:
              x2_movement = -7
          if x2_movement &gt; 7:
              x2_movement = 7
          if y2_movement &lt; -7:
              y2_movement = -7
          if y2_movement &gt; 7: 
              y2_movement = 7
  
          #COLLISION (WALL) P1
  
          if square1.colliderect(wall_left):
              player2_health -= 0.5
              x_movement = 0
              y_movement = 0
              if keys_pressed[pygame.K_RIGHT] == 1:
                  x_movement += 1
  
          if square1.colliderect(wall_right):
              player2_health -= 0.5
              x_movement = 0
              y_movement = 0
              if keys_pressed[pygame.K_LEFT] == 1:
                  x_movement += -1
  
          #COLLISION (WALL) P2
  
          if square2.colliderect(wall_left):
              player1_health -= 0.5
              x2_movement = 0
              y2_movement = 0
              if keys_pressed[pygame.K_d] == 1:
                  x2_movement += 1
  
          if square2.colliderect(wall_right):
              player1_health -= 0.5
              x2_movement = 0
              y2_movement = 0
              if keys_pressed[pygame.K_a] == 1:
                  x2_movement += -1
  
  
          #COLLISION (ATTACK) P1
          if square1.colliderect(square2) and keys_pressed[pygame.K_g] == 1:
              player2_health -= 1
  
          #COLLISION (ATTACK) P2
          if square2.colliderect(square1) and keys_pressed[pygame.K_p] == 1:
              player1_health -= 1
  
          #JUMPING P1
          if keys_pressed[pygame.K_w] == 1:
              if jumping2 == False:
                  jumping2 = True
  
                  y2_movement = -30
                  accely2 = 1
  
          square2 = square2.move(x2_movement, y2_movement)
  
          x2_movement += accelx2
          y2_movement += accely2
  
          if jumping2 == True:
              if square2.y &gt;= 350:
                  jumping2 = False
  
                  square2.y = 350
                  y2_movement = 0
                  accely2 = 0
  
          #JUMPING P2
          if keys_pressed[pygame.K_UP] == 1:
              if jumping == False:
                  jumping = True
  
                  y_movement = -30
                  accely1 = 1
  
          square1 = square1.move(x_movement, y_movement)
  
          x_movement += accelx1
          y_movement += accely1
  
          if jumping == True:
              if square1.y &gt;= 350:
                  jumping = False
  
                  square1.y = 350
                  y_movement = 0
                  accely1 = 0
  
          pygame.display.update()
          pygame.time.delay(20)
  
          if player2_health == 0 and player1_health !=0:
              pygame.time.delay(400)
              player1wins()
              pygame.time.delay(3000)
              drawmenu()
              break
          elif player1_health == 0 and player2_health !=0:
              pygame.time.delay(400)
              player2wins()
              pygame.time.delay(3000)
              drawmenu()
              break
          if player1_health == 0 and player2_health == 0:
              pygame.time.delay(400)
              tie()
              pygame.time.delay(3000)
              drawmenu()
              break
  </code></pre>