Framerate affect the speed of the game

You have to calculate the movement per frame depending on the frame rate.

pygame.time.Clock.tick returns the number of milliseconds since the last call. When you call it in the application loop, this is the number of milliseconds that have passed since the last frame. Multiply the objects speed by the elapsed time per frame to get constant movement regardless of FPS.

For instance define the distance in number of pixel, which the player should move per second (move_per_second). Then compute the distance per frame in the application loop:

move_per_second = 500
FPS = 60
run = True
clock = pygame.time.Clock() 
while run:
    ms_frame = clock .tick(FPS)
    move_per_frame = move_per_second * ms_frame / 1000  

    # [...]

Leave a Comment