Setting a fixed FPS in Pygame, Python 3

The clock.tick returns the time since the last call to clock.tick. Use that value and multiply all your speeds with it when you move.
Example

dt = clock.tick(60)
player.position.x += player.xSpeed * dt
player.position.y += player.ySpeed * dt

This way your player will always move at the same speed independent of what you put into the clock.tick() function.

Important is to only call clock.tick() once per frame.

Leave a Comment