Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laggy empty project at 60FPS

@Override
public void create() {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
}

@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
if (x < 0 || x > 400) {
    speed = -speed;
}
x += speed * Gdx.graphics.getDeltaTime() * 60;
Gdx.app.log("delta",Gdx.graphics.getDeltaTime()+"");

batch.begin();
batch.draw(img, x, 0);
batch.end();
}

I had a problem and i created a new project. The problem libgdx tries to keep 60FPS and avarage deltatime is ~16ms.Some renders take +20ms then next render takes 12ms(render1 + render2 = 32ms) to achieves 60FPS. That makes game laggy. As you can see i don't have anything in the project and it is the same in desktoplaunch. How did you solve this ?

Note: I also tried reqeustRendering. But it is the same thing if the render takes more time than the average. I also tried to wait some time for the render if that is less than 16ms. It didn't help either. It doesn't have any GC problem. I use Libgdx 1.6.4.

like image 854
Redugsix Avatar asked Nov 09 '22 07:11

Redugsix


1 Answers

Do not log output in the render loop

Remove the line Gdx.app.log("delta",Gdx.graphics.getDeltaTime()+""); as this writes output to the log, which slows down your render loop dramatically.

like image 77
Tobias G Avatar answered Nov 15 '22 13:11

Tobias G