class BackgroundManager(pygame.sprite.Sprite): stars=[ ] last_stars=[ ] def __init__(self): for x in range(init_stars): self.add_star() def update(self): counter=0 for star in self.stars: if star.top > WIN_RESY: del self.last_stars[counter] else: self.last_stars[counter]=pygame.Rect(star.topleft,(star.width+2, star.height+2)) counter+=1 counter=0 for star in self.stars: if star.top > WIN_RESY: del self.stars[counter] #del self.last_stars[counter] self.add_star() else: #self.last_stars[counter]=pygame.Rect(star.topleft,(star.width+2, star.height+2)) star.move_ip(0,star.get_speed()) counter+=1 def draw(self): for star in self.stars: surface.fill((255,255,255),star) return self.stars def clear(self): for star in self.last_stars: surface.fill((0,0,0),star) def add_star(self): size=random.randint(3,6) x=random.randint(0,WIN_RESX) rect=star(x,0,size,size) rect.set_speed(random.randint(8,BG_Speed)) self.stars.append(rect) self.last_stars.append(rect)