Example #1
0
class BackgroundImage(BackgroundObject):
  def __init__(self, speed, *groups):
    BackgroundObject.__init__(self, (0, 0), speed, *groups)

    self.image = pygame.image.load('gfx/terrain/example_editor.png').convert_alpha()
    self.rect = pygame.Rect((0, app.screen_height - self.image.get_height()),
                            (0, 0))
    self.clock = Clock()

  def update(self):
    delta_y = round(self.clock.frame_span() * self.speed / 1000)
    self.rect.move_ip(0, delta_y)
Example #2
0
class BackgroundObject(pygame.sprite.Sprite):
  def __init__(self, pos, speed, *groups):
    pygame.sprite.Sprite.__init__(self, *groups)
    self.rect = pygame.Rect(pos, (0, 0))
    self.speed = speed
    self.clock = Clock()

  def update(self):
    delta_y = round(self.clock.frame_span() * self.speed / 1000)
    self.rect.move_ip(0, delta_y)
    if self.rect.top >= app.screen_height:
      self.kill()
      del self

  def left(self):   return self.rect.left
  def right(self):  return self.rect.right
  def top(self):    return self.rect.top
  def bottom(self): return self.rect.bottom