Code Monkey home page Code Monkey logo

Comments (4)

crykn avatar crykn commented on May 23, 2024 2

How about Gdx.graphics.setForegroundFPS(int)?

from libgdx.

AnotherCoder1 avatar AnotherCoder1 commented on May 23, 2024

I think this is so simple to implement by ourself the consumer coders that consume this libgdx library.

First, you declare a function that takes in the elapsed time between the two frames. So that, later you can pass delta time to the function.
in the render() method of Game class or Screen class.

Let's take one example if you want to limit it to 60FPS, then each elapsed time in between two frames should be 1/60 second or 0.01667. Then, you check if the elapsed time is less than that, you need to add that up so it becomes 0.01667. To get how much you need to add is 0.01667 - elapsedTime, and store it as temporary variable. Meaning, you add the elapsedTime with this temporary variable so it becomes 0.01667 second every frame.

If it is higher you substract by that amount.
I.e elapsedTime-= (elapsedTime-0.01667).
Hopefully, you get the idea.
Then, you just return that number.
Then, you can use that return value in the render() method.

from libgdx.

Andrei0100 avatar Andrei0100 commented on May 23, 2024

AnotherCoder1

I tried everything but only Thread.sleep works, It would be better to have a built-in method like
"Gdx.graphics.setFrameRateLimit(targetFPS);" for straightforward frame rate control. Thanks for your suggestions!

from libgdx.

Andrei0100 avatar Andrei0100 commented on May 23, 2024

How about Gdx.graphics.setForegroundFPS(int)?

Oh wow... for some reason I didn't see it, THANK YOU!

from libgdx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.