Pygame sprites not rendering

I’m making a simple physics simulator in python, using pygame for rendering and such. However I can’t seem to be able to render more than 1 ball at a time. I’ve tried google for a few hours, and also using things like self.rect and trying to draw outside the Ball class (in the main loop). But nothing seems to work.

Only one ball gets rendered at a time, but there are 5 balls calculating physics. The physics seem fine when printing positions of every ball, and they aren’t overlapping due to the random start positions and velocities.

Repl link: and are the important files
(maybe too but I don’t think so)

Possible places for problems:

- - line 46-51

  # render all balls (problem most likely here)
  for ball_class in game.Game.all_balls:
      (ball_class.Bounds.x, ball_class.Bounds.y)

- - line 32-38

  # draw ball
  image =
    (Bounds.r, Bounds.r),


wrap all variables of the ball class inside a super().__init__() like this:

class Ball(pygame.sprite.Sprite):
  def __init__(self): # __init__
    super().__init__() # then super().__init__()
    self.Bounds = Bounds()
    self.Vel = Vel()
    # the balls fill color
    self.color = tuple(random.randint(100, 255) for _ in range(3))

    # make surface
    self.surface = pygame.Surface((self.Bounds.d, self.Bounds.d))
    self.surface.set_colorkey((0, 0, 0)) # transparency

Why does this work:
I do not know the full aspect, but pygame seems to require super classes for the pygame.sprite.Sprite class

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.