java – 如何根据屏幕分辨率在libgdx中缩放精灵?

我试图缩放纹理以适应屏幕宽度.这是我试过的,但它只是重复纹理.它不会缩放.

在init方法中:

TextureLoader.TextureParameter param = new TextureLoader.TextureParameter();
        param.minFilter = Texture.TextureFilter.MipMapLinearLinear;
        param.genMipMaps = true;
        param.wrapU = Texture.TextureWrap.ClampToEdge;
        param.wrapV = Texture.TextureWrap.ClampToEdge;
        manager.load("textures/texture.png", Texture.class, param);

在渲染方法中:

Texture tex = manager.get("textures/texture.png", Texture.class);
float scale = (float)( (float)Gdx.graphics.getWidth() / (float)(tex.getWidth()));

batch.begin();
Sprite s = new Sprite(tex, 0,0,tex.getWidth(),tex.getHeight());

s.setPosition(0, 0);
s.setOriginCenter();
//s.setScale(scale);
s.setSize(Gdx.graphics.getWidth(), scale * tex.getHeight());
s.setOrigin(0,0);
s.draw(batch);
batch.end();

有人有什么想法我在做错什么?

最佳答案
显然这是因为我使用mipmaps.没有mipmapping,精灵比例适当.

param.minFilter = Texture.TextureFilter.MipMapLinearLinear;
param.genMipMaps = true;

转载注明原文:java – 如何根据屏幕分辨率在libgdx中缩放精灵? - 代码日志