我试图缩放纹理以适应屏幕宽度.这是我尝试过的,但它只是重复纹理.它没有扩展它.
在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();
有谁知道我做错了什么?