How do I cap my framerate at 60 fps in Java?

后端 未结 10 1821
离开以前
离开以前 2021-02-07 08:01

I am writting a simple game, and I want to cap my framerate at 60 fps without making the loop eat my cpu. How would I do this?

10条回答
  •  半阙折子戏
    2021-02-07 08:54

    What I have done is to just continue to loop through, and keep track of when I last did an animation. If it has been at least 17 ms then go through the animation sequence.

    This way I could check for any user inputs, and turn musical notes on/off as needed.

    But, this was in a program to help teach music to children and my application was hogging up the computer in that it was fullscreen, so it didn't play well with others.

提交回复
热议问题