title: Trying to properly iterate through pygame sprite group
body: <p>So I am building a simple infinite run game for school and I am stuck on trying to spawn the obstacles. I am trying to check each obstacle sprite and if it has gone off the screen (the background and obstacles move from right to left). If it has gone off screen, I want to remove the sprite and set up another one on the right side of the screen. But every time an obstacle goes off the left side of the screen, an infinite amount of obstacles start spawning. I am new to pygame and python in general. Any help would be greatly appreciated. Thanks in advance.</p>
  
  <pre><code>def obstacle_off_screen(self):
      numDeleted = 0
      for cur_sprite in self.all_objects_list:
          print("first loop")
          if cur_sprite.rect.x &lt; 0:
              print("second")
              cur_sprite.kill
              numDeleted += 1
      while numDeleted != 0:
          print("third")
          self.add_obstacle()
          numDeleted -= 1
  
  def add_obstacle(self):
      #add parameters
      if self.get_Speed() == 15:
          x = 1000
          y = 400
      elif self.get_Speed() == 20:
          x = 1000
          y = 400
      elif self.get_Speed() == 25:
          x = 1000
          y = 400
      elif self.get_Speed() == 30:
          x = 1000
          y = 400
  
      self.all_objects_list.add(Obstacle('src/paw.gif', [x, y]))
  </code></pre>
  
  <p>For now, I only have one obstacle that I initially spawn</p>