title: All Sprites are moved to same coordinates?
body: <p>The code below is basically a test for me to get to know Sprites and Groups. It is supposed to create 10 instances of the <code>Ball</code> class, and then randomly position and move each, and bounce them around the screen. The problem is, whilst they all get positioned independently, for some reason they all seem to inherit the same coordinates during the loop and so there appears to be only 1 ball bouncing around.</p>
  
  <pre><code>import pygame, sys, random
  
  pygame.init()
  
  size = width, height = 640, 400
  screen = pygame.display.set_mode(size)
  
  class Ball(pygame.sprite.Sprite):
      image = pygame.image.load('assets/ball.gif').convert()
      rect = image.get_rect()
      max_speed = 2
      speed = 0
      direction = [1, 1]
  
      def randomize(self):
          random.seed()
          self.rect.x = random.random() * width
          self.rect.y = random.random() * height
          self.speed = random.random() * self.max_speed
          print ('%s %s %s') % (self.rect.x, self.rect.y, self.speed)
  
      def update(self):
          if self.rect.left &lt; 0:
              self.direction[0] =  1
          if self.rect.right &gt; width:
              self.direction[0] = -1
          if self.rect.top &lt; 0:
              self.direction[1] =  1
          if self.rect.bottom &gt; height:
              self.direction[1] = -1
  
          self.rect.x += self.speed * self.direction[0]
          self.rect.y += self.speed * self.direction[1]
  
  layers = pygame.sprite.LayeredUpdates()
  black = 0, 0, 0
  clock = pygame.time.Clock()
  
  for i in range(0,10):
      ball = Ball()
      ball.randomize()
      layers.add(ball)
  
  while True:
      for event in pygame.event.get():
          if event.type == pygame.QUIT: sys.exit()
  
      screen.fill(black)
      layers.update()
      layers.draw(screen)
      pygame.display.flip()
      clock.tick(30)
  </code></pre>
  
  <p>Below is the output from <code>Ball.randomize()</code>:</p>
  
  <pre><code>454 317 0.268577946144
  560 175 0.777246064841
  446 161 1.71602882781
  337 221 0.298744471713
  9 122 1.19615176471
  304 351 1.45267115709
  255 397 0.478593408657
  135 213 1.04660721161
  96 26 0.758952705602
  389 106 0.954778970584
  </code></pre>
  
  <p>I assume I'm not understanding how pygame.image works and that somehow Ball.image is actually the same object shared across all instances, however I don't really know how to prove it, nor how to resolve it.</p>