Answer the question
In order to leave comments, you need to log in
How to fix "pixelated" camera movement in libgdx?
The standard orthographic camera (OrthographicCamera) is used. When the position is changed to float, the position is changed to int (i.e. the coordinate is rounded). As a result, the image is shifted "pixel by pixel". Is it possible to draw a non-pixel perfect result?
I googled seemingly similar problems - options using vector3.scl () and vector3.lerp (), but only my hands are crooked, or the problems are not quite the same, or the version of libgdx is different.
For example, consider 3 frames with camera movement +.5f horizontally (x-coordinate):
Frame 1: Nothing happens
Frame 2: Shift one pixel to the left
Frame 3: Nothing changes
Wait:
Frame 1: Shift 0.5 left
Frame 2 : Shift 0.5 to the left
Frame 3: Shift 0.5 to the left
At the same time, applying interpolation to the texture ( setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.MipMapLinearLinear) ) did not bring the expected result. From which I conclude that the problem is specifically in the camera.
Side effect:
Zooming ignores interpolation when using viewport:
Environment:
- Libgdx 1.5.6.
- JDK 1.8 x64
- Intel HD Graphics 4600 (i.e. support for OpenGL up to 4.3).
- Win 7 (including LwjglApplication)
The code itself is quite obvious:
// camera == OrthographicCamera
// sprite == Sprite
// batch == SpriteBatch
@Override
public void render() {
camera.update();
camera.position.set(new Vector3(camera.position.x + 0.1f, camera.position.y, 0));
batch.setProjectionMatrix(camera.combined);
batch.setTransformMatrix(camera.view);
// render
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
sprite.draw(batch); // Отрисовка белой картиночки с синими линиями
batch.end();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question