Im new in Libgdx. I tried to make pixel art game but i have a problem. When i render sprite with texture, pixels are deformated stretched (i added red arrows o second image). I made 400x400 window and scaled sprite to fit screen width in 1:1 ratio (sprite width = screen width and sprite heigh = screen width too)
Images:
This is a code of main game class:
public class Pixel implements ApplicationListener {
SpriteBatch batch;
Texture testTexture;
Sprite testSprite;
int w;
int h;
@Override
public void create() {
batch = new SpriteBatch();
testTexture = new Texture(Gdx.files.internal("test.png"));
testSprite = new Sprite(testTexture);
testSprite.setSize(w, w);
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
testSprite.draw(batch);
batch.end();
}
@Override
public void resize(int width, int height) {
w = width;
h = height;
create();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
and this is desktop starter class:
public class DesktopLauncher {
public static void main(String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = 400;
config.height = 400;
new LwjglApplication(new Pixel(), config);
}
}