Description:
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.
Problem:
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:
https://replit.com/@ByteDice/Ball-Pit?v=1#main.py
main.py and ball.py are the important files
(maybe game.py too but I don’t think so)
Possible places for problems:
- main.py - line 46-51
# render all balls (problem most likely here)
for ball_class in game.Game.all_balls:
game.Game.display.blit(
ball_class.surface,
(ball_class.Bounds.x, ball_class.Bounds.y)
)
- ball.py - line 32-38
# draw ball
image = pygame.draw.circle(
surface,
color,
(Bounds.r, Bounds.r),
Bounds.r
)