I have a partner in this Pygame project. So it's for fun, and it's Snake.
He says to use time.sleep instead of pygame.clock since it is 'better'. Is his choice better, or is mine better?
Pygame: pygame.time.Clock, or time.sleep
1.1k views Asked by tdserapio At
1
Use
pygame.time.Clockto control the frames per second and thus the game speed.The method
tick()of apygame.time.Clockobject, delays the game in that way, that every iteration of the loop consumes the same period of time. Seepygame.time.Clock.tick():That means that the loop:
runs 60 times per second.
For comparison,
time.sleepjust waits a constant amount of time. If you want to get a constant frame rate you need to usepygame.time.Clock.tick.