簡體   English   中英

如何根據屏幕分辨率在libgdx中縮放精靈?

[英]How to scale sprites in libgdx according to screen resolutions?

我試圖縮放紋理以適應屏幕寬度。 這是我嘗試過的,但它只是重復紋理。 它沒有擴展它。

在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();

有誰知道我做錯了什么?

顯然這是因為我使用的是mipmap。 沒有mipmapping,sprite會適當縮放。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM