1
\$\begingroup\$

I'm trying to implement a frame rate feature, and I have noticed that using 60 frames per second causes the screen to leave a drawn trail of textures, when there is movement.

Here's the code I'm using to make the frame rate feature:

public void render(float deltaT){
    currentLevel.updateWorld(deltaT);

    if((fps+=deltaT) >= 1.0/60.0){
        fps = 0;
    }else
        return;

    super.render(deltaT);
    Gdx.gl.glClearColor(103 / 255f, 69 / 255f, 117 / 255f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

    currentLevel.updateScreen(deltaT, gameCamera);
}

The currentLevel.updateWorld updates the game's logic. The currentLevel.updateScreen method updates the camera's position, drawn to the screen.

\$\endgroup\$
  • \$\begingroup\$ @Charanor Hi, I'm trying to limit frame rate while using the normal render speed for the game's logic, is there any other way to do this besides what I'm doing? I've tried turning vSync ON but it still gives me a sprite trail when the my character moves. \$\endgroup\$ – Joao May 12 '17 at 15:21
  • \$\begingroup\$ @Joao there's no real reason to limit one but not the other. Not limiting the framerate will just increase your CPU load and use unnecessary resources and battery (if you're on mobile) for no real gain. As for the sprite trail that's probably a render problem so you will have to supply your rendering code if we're to help you fix it. \$\endgroup\$ – Charanor May 12 '17 at 18:29
3
\$\begingroup\$

You don't need to limit the framerate yourself within LibGDX. The framework handles that for you. You can enable vsync in your game by adding this line to your desktop configuration:

config.vSyncEnabled = true;

Or in-game using

Gdx.graphics.setVSync(true);
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.