How to make timer for a game loop?

前端 未结 5 1756
别跟我提以往
别跟我提以往 2021-02-06 16:21

I want to time fps count, and set it\'s limit to 60 and however i\'ve been looking throught some code via google, I completly don\'t get it.

5条回答
  •  醉梦人生
    2021-02-06 17:26

    If you want 60 FPS, you need to figure out how much time you have on each frame. In this case, 16.67 milliseconds. So you want a loop that completes every 16.67 milliseconds.

    Usually it goes (simply put): Get input, do physics stuff, render, pause until 16.67ms has passed.

    Its usually done by saving the time at the top of the loop and then calculating the difference at the end and sleeping or looping doing nothing for that duration.

    This article describes a few different ways of doing game loops, including the one you want, although I'd use one of the more advanced alternatives in this article.

提交回复
热议问题