Setting a fixed FPS in Pygame, Python 3

陌路散爱 提交于 2019-12-05 20:18:52

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 regardless of what you put into the clock.tick() function.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!