In Pygame, normalizing game-speed across different fps values

后端 未结 4 1178
迷失自我
迷失自我 2021-01-05 12:05

I\'m messing around with Pygame, making some simple games just to learn it. However, I\'m having a hard time implementing fps the way that I want.

From what I unders

4条回答
  •  感情败类
    2021-01-05 12:24

    While @monkey's answer is the complete datadump, you should probably have a look over the pygame docs on time.Clock again. The optional framerate argument to Clock.tick() sets a ceiling on FPS, not a fixed FPS; in other words, if your game loop takes longer than that amount of time to complete, the game will lag if you are assuming that passing that value ensures a fixed game speed. It looks like Clock.get_time() and Clock.get_raw_time() are the things to use to get the execution time of the last game loop, then you can calculate the behavior of your game elements from that.

提交回复
热议问题