Search code examples
javalibgdx

Low fps on LibGDX


Without this code fps is 60-65. But when i use this code, fps down to 50.

Another problem is that the FPS is too low on some devices. However, the game is quite simple. I'm using ShapeRenderer for all shapes. Game is here: link

    try {
            Thread.sleep((long)(1000/60-Gdx.graphics.getDeltaTime()));
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Edit: I solved this problem using this code --> link.


Solution

  • You can limit the FPS to any value you want in a libgdx application by defining the foregroundFPS in the config of your app loader.

    LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
        config.width = 640;
        config.height = 480;
        config.foregroundFPS = 60; // <- limit when focused
        config.backgroundFPS = 60; // <- limit when minimized
        config.samples =2; // AA for shape renderer.. not textures!
        new LwjglApplication(new libgdxapp(), config);
    

    android config

    Continuous rendering