title: Source object must be a surface
body: <p>I am encountering a problem which says that the source object must be a surface. I asked this question before, and the answer worked, but now it's a different scenario. I looked at the previous question I had, and I couldn't figure out how to solve it.</p>
  <p>Error Message:</p>
  <pre><code>Traceback (most recent call last):
  File &quot;C:\Users\Daniel\Desktop\Thing.py&quot;, line 22, in &lt;module&gt;
  level.run()
  File &quot;C:\Users\Daniel\Desktop\level2.py&quot;, line 131, in run
  self.clouds.draw(self.display_surface, self.world_shift)
  File &quot;C:\Users\Daniel\Desktop\decoration.py&quot;, line 67, in draw
  self.cloud_sprites.draw(surface)
  File &quot;C:\Users\Daniel\AppData\Local\Programs\Python\Python310\lib\site- 
  packages\pygame\sprite.py&quot;, line 551, in draw
  self.spritedict.update(zip(sprites, surface.blits((spr.image, spr.rect) for 
  spr in sprites)))
  TypeError: Source objects must be a surface
  </code></pre>
  <p>Basically I am trying to blit things onto a surface, and the thing that confuses me the most is that it worked when I was trying to blit water onto the screen, it had the exact same code but instead of 'cloud' it had 'water', however the water blitting worked while the cloud did not.</p>
  <p>Water Class:</p>
  <pre><code>class Water:
  def __init__(self, top, level_width):
      water_start = -width
      water_tile_width = 192
      tile_x_amount = int((level_width + width) / water_tile_width)
      self.water_sprites = pygame.sprite.Group()
  
      for tile in range(tile_x_amount):
          x = tile * water_tile_width + water_start
          y = top
          sprite = AnimatedTile(192, x, y, (x, y), 
          'C:\\Desktop\\Game\\decoration\\water')
          self.water_sprites.add(sprite)
  
  
  def draw(self, surface, shift):
      self.water_sprites.update(shift)
      self.water_sprites.draw(surface)
  </code></pre>
  <p>Cloud Class:</p>
  <pre><code>class Clouds:
  def __init__(self, horizon, level_width, cloud_number):
      min_x = -width
      max_x = level_width + width 
      min_y = 0
      max_y = horizon
      cloud_surface_list = 'C:\\Desktop\\Game\\decoration\\clouds'
      self.cloud_sprites = pygame.sprite.Group()
  
      for cloud in range(cloud_number):
          cloud = choice(cloud_surface_list)
          x = randint(min_x, max_x)
          y = randint(min_y, max_y)
          sprite = StaticTile(0, x, y, (x, y), 
          'C:\\Desktop\\Game\\decoration\\clouds')
          self.cloud_sprites.add(sprite)
  
  def draw(self, surface, shift):
      self.cloud_sprites.update(shift)
      self.cloud_sprites.draw(surface)
  </code></pre>
  <p>As you can see the draw method is the exact same code, pretty much. The only difference that I can spot that could be causing the problem would be the inheritance. <code>Water</code> inherits from a class called <code>AnimatedTile</code> while <code>Clouds</code> inherits from <code>StaticTile</code>. I will put the code for both of those here:</p>
  <p>AnimatedTile:</p>
  <pre><code>class AnimatedTile(Tile):
  def __init__(self, size, x, y, pos, path):
      super().__init__(size, x, y, (x, y))
      self.frames = import_folder(path)
      self.frame_index = 0
      self.image = self.frames[int(self.frame_index)]
  
  def animate(self):
      self.frame_index += 0.15
  
      if self.frame_index &gt;= 4:
          self.frame_index = 0
  
      self.image = self.frames[int(self.frame_index)]
  
  def update(self, shift):
      self.animate()
      self.rect.x += shift
  </code></pre>
  <p>StaticTile:</p>
  <pre><code>class StaticTile(Tile):
  def __init__(self, size, x, y, pos, surface):
      super().__init__(size, x, y, (x,y))
      self.image = surface
      self.surface = surface
  </code></pre>
  <p>Drawing and Updating:</p>
  <pre><code>self.clouds.draw(self.display_surface, 
  self.world_shift)
  </code></pre>
  <p>*I know these are surfaces because I drew them the same exact way to blit the water onto the screen (<code>self.water.draw(self.display_surface, self.world_shift)</code> and it worked.</p>
  <p>Other code:</p>
  <pre><code>class Level:
      def __init__(self, level_data, surface):
  
          self.display_surface = surface
          self.world_shift = -8
  </code></pre>
  <p>Tile:</p>
  <pre><code>class Tile(pygame.sprite.Sprite):
  def __init__(self, size, x, y, pos):
      super().__init__()
      self.image = pygame.Surface((size, size))
      self.rect = self.image.get_rect(topleft = pos)
  
  def update(self, shift):
      self.rect.x += shift
  </code></pre>
  <p><code>world_shift</code> is basically how fast the level is moving (negative means right, positive means left)</p>
  <p>I'm sorry if this sounds stupid and the answer is obvious.</p>