Setting FPS



  • I am encountering unavoidable slowdown in my project, and I would like to limit it to (e.g.) 30fps to have extra time each frame.

    Is the best way to do that similar to the example code shown for the time() function? Namely, at the end of each frame, make the program "wait" until 1/30 of a second has passed?

    (I tried with the sleep() function, but that resulted in more showdown)



  • The following should do the trick, but the fps number indicator does not seem to be influenced by the sleep command:

    int fps = 30
    loop
        sleep((1/fps)  - deltaTime())
        update()
    repeat
    

  • Fuze Team

    I'm not entirely following what you are trying to acheive because using sleep won't give you any extra usable time since Fuze will just sleep during that time and you won't be able to do anything. Although the technical answer I was given wasn't quite this straightforward, you should consider that update() will automatically wait for the next vblank if you want to use old-school terms. But that's only really of any consequence if you have any spare time left which it sounds like you don't.

    I think I get what you want, and the simple answer is that I don't think you can do it. The example in the help for time is allowing you to wait for a period of seconds to pass and that's certainly not what you want.


  • F

    @PB____
    I like how you've done that it's very clever



  • @Martin
    Originally I read the question the same way. I did notice that FUZE doesn't completely pause during a sleep command (you can still use + to close the game, and the FPS numbers keep refreshing). But I didn't assume that FUZE would schedule garbage collection tasks during a sleep command, or anything fancy like that.

    However, if the performance of your game varies between 30 and 60 fps all the time, then the user may notice performance issues. If you cap the fps at a consistent 30 fps, then the user gets used to it for the game and have a better user experience overall. So on second thought, I assumed this was the nature of the original question :)



  • @PB___ Thank you for your code snippet! It makes sense, and I look forward to trying it when I am on front of my Switch.

    And you summarized my issue well: Rather than let the game fluctuate between about 45 and 60 fps (depending on things like how many enemies are present), I thought "pinning" the rate to 30 fps would be smoother. I saw that suggested on another thread, but could not find that nor how to implement.


Log in to reply