如何根据屏幕分辨率在libgdx中缩放精灵?
我正在尝试缩放纹理以适应屏幕宽度。这是我尝试过的,但它只是重复纹理。它不会缩放它。
在初始化方法中:
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();
有没有人知道我做错了什么?