0

我对 libGDX 有疑问...

我想调整我的图片大小,但我不知道找到这个比例...你能帮帮我吗?

我的代码:

@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}


@Override
public void show() {
    // TODO Auto-generated method stub
    float x = 0;
    this.w = Gdx.graphics.getWidth();
    this.h = Gdx.graphics.getHeight();
    System.out.println(w);
    System.out.println(h);
    camera = new OrthographicCamera(1, 1);

    batch = new SpriteBatch();

    imgAbalone = new Texture(Gdx.files.internal("data/AbaloneCS5.gif"));
    imgFond = new Texture(Gdx.files.internal("data/parquet.jpg"));
    imgAbalone.setFilter(TextureFilter.Linear, TextureFilter.Linear);

    TextureRegion region = new TextureRegion(imgAbalone, 0, 0, 700, 700);
    spriteAbalone = new Sprite(region);
    spriteAbalone.setSize(0.9f , 0.9f);
    spriteAbalone.setOrigin(spriteAbalone.getWidth()/2, spriteAbalone.getHeight()/2);
    spriteAbalone.setPosition(-spriteAbalone.getWidth()/2, -spriteAbalone.getHeight()/2);
    TextureRegion regionFond = new TextureRegion(imgFond, 0, 0, 1000,1000);
    spriteFond = new Sprite(regionFond);
    spriteFond.setSize(1, 1);
    spriteFond.setOrigin(0,0);
    spriteFond.setPosition(-spriteFond.getWidth()/2, -spriteFond.getHeight()/2);
}

我不知道在 resize () 里放什么

4

2 回答 2

0

Not 100% sure whether this is right or not because in my own project I abstracted this code away a long time ago, but try:

camera.setToOrtho(false, width, height);
camera.update();
spriteBatch.setProjectionMatrix(camera.combined);
shapeRenderer.setProjectionMatrix(camera.combined);//if you have one
于 2013-10-28T23:46:24.467 回答
0

做一件事,像这样设置相机视口..

    float scrw=320;
    float scrh=480;
    camera = new OrthographicCamera();
    camera.setToOrtho(false, scrw, scrh);
    camera.update();

这里 scrw 是您的视口宽度,您可以根据需要设置它,而 scrh 是您的视口高度。使用这个你没有太多调整任何东西..

但是如果您想以任何方式调整大小,可以使用此代码

    float hh = (float) (Gdx.graphics.getWidth() / 320f);

然后

    sprite.setScale(hh);
于 2013-10-29T05:47:54.797 回答