Hi guys.
Im having a bit of a problem.
I currently adapted my game to run at 30 fps…
But, i just noticed that android config, dont have the same desktop method to limit fps…
What should i do? I saw someone talking about Thread.sleep, but its libgdx and i dont have access to all threads?
Also, why you need to limit fps? You should use delta value for all your movement calculations and let Android handle your frame rate.
If device have low fps your objects need to move faster and if device have high fps your objects need to move slower.
Do not control your movements with fixed frame rate.
Gdx.graphics.getDeltaTime returns time in seconds. So to convert to millis you could multiply by 1000.
As for limiting the framerate to 30 fps, you could do:
//stores how much time has passed since the last frame.
private float timeSpent;
public void render() {
timeSpent += Gdx.graphics.getDeltaTime();
if(timeSpent > 1) {
//The following loop will try to catch up if you're not at 30 fps.
//This code will reset the amount of time it needs to spend catching up if there's too
//much to do (maybe because the device can't keep up).
timeSpent = 1 / 30F;
}
while (timeSpent >= 1 / 30F) {
//Run your code
timeSpent -= 1 / 30F;
}
}
You can use Non-continuous rendering, and then you can just use any ol’ game loop, calling requestRendering() each loop around. Note however that input events will also trigger the rendering, so you should still use the graphics.getDeltaTime() in your calculations to make sure stuff won’t go wack when input is handled.
Also make sure the game loop is not in the render thread!