@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.
Remove the line
Gdx.app.log("delta",Gdx.graphics.getDeltaTime()+"");
as this writes output to the log, which slows down your render loop dramatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With