Learn Before
Using Clocks in Pygame
Clocks in PyGame can be used to track an amount of time and control a game's FPS. The clock submodule is a child module of pygame.time. You can start by initializing a Clock object using the following command.
pygame.time.Clock()
You can use the tick method to update the clock and also control framerate. This method should be called once per frame. The optional framerate parameter will set the maximum framerate of your game--for example, passing in 40 will ensure your game never goes above 40 FPS.
pygame.time.Clock.tick(frames)
You can get the time that has passed between the last two calls to Clock().tick() by using get_time.
pygame.Clock.get_time()
You can also compute the framerate (by taking the average of the last ten calls to Clock.tick()) by using get_framerate.
pygame.get_fps()
0
1
Tags
Python Programming Language
Data Science