简体   繁体   English

如何在LibGDX中调整纹理大小?(Android)

[英]How do I resize my textures in LibGDX?(Android)

I'm starting to use LibGDX, and wanted to easily port my game to different screen size(in Android). 我开始使用LibGDX,并想轻松地将我的游戏移植到不同的屏幕尺寸(在Android中)。 I have a background texture, which I want to scale to the currently used resolution. 我有一个背景纹理,我想缩放到当前使用的分辨率。 The game works on 1920x1080, but when I use a lower resolution the texture is cut, how do I change it to the currently screen size? 该游戏可以在1920x1080上运行,但是当我使用较低的分辨率时,会剪切纹理,如何将其更改为当前的屏幕尺寸?

I use 我用

batch = new SpriteBatch();
bkTexture = new TextureRegion(new Texture(Gdx.files.internal("menu.png")),0 , 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

and

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(delta);
batch.begin();
batch.draw(bkTexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
batch.end();
stage.draw();

在纹理上添加滤镜?

myTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

Try this: 尝试这个:

bkTexture = new TextureRegion(new Texture(Gdx.files.internal("menu.png")),0 , 0); bkTexture = new TextureRegion(new Texture(Gdx.files.internal(“ menu.png”)),0,0);

instead of 代替

bkTexture = new TextureRegion(new Texture(Gdx.files.internal("menu.png")),0 , 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); bkTexture = new TextureRegion(new Texture(Gdx.files.internal(“ menu.png”)),0,0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());

Using the 2nd line you extract a texture region with the size Gdx.graphics.getWidth(), Gdx.graphics.getHeight() at position 0,0 of the menu.png texture. 使用第二行,在menu.png纹理的位置0,0处提取大小为Gdx.graphics.getWidth(),Gdx.graphics.getHeight()的纹理区域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM