2
\$\begingroup\$

I'm having this issue that is very annoying. Somehow the texture of the player body is getting blurry and leaving a slight trail with its colors when moving it. The interesting fact is, this only happens when the player is moving in the air. I set linear velocity to move the player on the ground and I'm applying force to center to move the player when he's jumping.

I also tried using just a simple sprite. I played with Texture Filters and it didn't change anything. I even tried different textures. I'm calling Gdx.gl.glClear, which should have solved this issue.

Here's the render method of my Screen class:

@Override
public void render(float delta) {
    Gdx.gl.glClearColor( 1, 0, 0, 1 );
    Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT );
    camera.update();
    game.batch.setProjectionMatrix(camera.combined);
    world.step(Gdx.graphics.getDeltaTime(), 6, 2);
    debugMatrix = game.batch.getProjectionMatrix().cpy().scale(pixelsToMeters, pixelsToMeters, 0);
    game.batch.setProjectionMatrix(camera.combined);
    tiledMapRenderer.setView(camera);
    tiledMapRenderer.render();
    game.batch.begin();
    player.update();
    player.render(game.batch);
    game.batch.end();
    debugRenderer.render(world, debugMatrix);
}

Here's the part in the player's update method where I move him if he's jumping. This is the only movement in the game that causes the texture to get blurry. Same thing for the left side except the "-" sign when applying force to center:

if (Gdx.input.isKeyPressed(Input.Keys.RIGHT) && !rightCollision) {
        playerDir = Direction.right;
        if (playerState == State.jumping) {
            playerBody.applyForceToCenter(250f, 0f, true);
        } else {
            playerState = State.walking;
            playerBody.setLinearVelocity(1.2f, 0f);
        }
    }

And here's the part that makes the player jump:

if (Gdx.input.isKeyJustPressed(Input.Keys.UP) && playerState != State.jumping) {
        playerBody.applyLinearImpulse(new Vector2(0, 500f), playerBody.getWorldCenter(), true);
        playerState = State.jumping;
    }
\$\endgroup\$

Your Answer

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

Browse other questions tagged or ask your own question.