alex czernenk
alex czernenk

Reputation: 203

LibGDX Scaling down

I've tried to scale down a 512 x 256 image of a rocket by setting the width and height directly. When I launch it the rocket image is pixely and very bad quality even though it is supposed a crisp vector image. I wanted to know how I would properly scale this down to still retain the quality.

 public GameScreen(){

        cam = new OrthographicCamera();
        cam.setToOrtho(false, 600, 800);

        batch = new SpriteBatch();
        img = new Texture(Gdx.files.internal("data/rocket.png"));
        batch.setProjectionMatrix(cam.combined);
    }

    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {

        cam.update();

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


        batch.begin();
        batch.draw(img,10, 10, 100, 60);
        batch.end();
    }

Upvotes: 0

Views: 163

Answers (1)

Burak Kurkcu
Burak Kurkcu

Reputation: 600

As Tenfour04 mentioned in comments you need to initialize Texture class with mipmaps enabled. Then set texture filters using setFilter method.

img = new Texture(Gdx.files.internal("data/rocket.png"), true);
img.setFilter(Texture.TextureFilter.MipMapLinearNearest, Texture.TextureFilter.Nearest);

Upvotes: 1

Related Questions