Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stuttering in even the simplest of projects

I made a small "game" to test some stuttering I had noticed in my actual game, and I can't for the life of me figure out why this is happening. I made the simplest possible project I could to test this out, but I still get pretty heavy stuttering. The FPS is still 60, but every few seconds, sometimes more, the game will stutter.

I have tried it on both mobile and a high-end pc, and oddly enough, it's more noticeable on the PC, though it still occurs on mobile.

I can't upload a video of it, since it's gone in the recording, so feel free to compile the project yourself if you want to test it. Here's the code:

public class LagTest extends ApplicationAdapter {
    SpriteBatch batch;
    Texture dot;
    float x;
    float y;
    float speed;
    float dotWidth;
    int screenWidth;

    @Override
    public void create () {
        batch = new SpriteBatch();
        dot = new Texture("dot.png");
        x = 100;
        y = Gdx.graphics.getHeight()/2 - dot.getHeight()/2;
        speed = 500;
        dotWidth = dot.getWidth();
        screenWidth = Gdx.graphics.getWidth();
    }

    @Override
    public void render () {
        Gdx.gl.glClearColor(0.2f, 0.4f, 0.8f, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(dot, x, y);
        batch.end();
        if (x < 0) {
            speed = 500;
        }

        if (x > screenWidth - dotWidth) {
            speed = -500;
        }
        x += speed * Gdx.graphics.getDeltaTime();
    }
}

If anyone have some clue to what could be causing this, I'm all ears.

Edit:

So here's something fun. This only seems to occur in windowed mode, not in fullscreen. This might also be why it works better on mobile. Perhaps this is a bug then?

like image 838
tobloef Avatar asked Oct 31 '22 19:10

tobloef


1 Answers

After trying some different methods (averaging delta / averaging raw delta / using raw delta / lowering frame rate to 30 / using a set delta each frame) getting the same stuttering on each one and then googling some on stuttering in windowed mode:

I would like to propose that the stuttering is not caused by LibGDX in itself, but rather is a general problem that occurs in windowed mode and which can have a number of different hardware-near causes. See here for one example and explanation: https://gamedev.stackexchange.com/questions/47356/why-would-a-borderless-full-screen-window-stutter-occasionally

like image 124
DHa Avatar answered Nov 15 '22 08:11

DHa