13

I have been fooling around with LibGDX for a while now, and wanted to easily port my programs to different systems. I have a background texture, which I want to scale to the currently used resolution. The image is 1920x1080, how do I change it to the currently used resolution at runtime?

4

2 回答 2

16

如果要在绘图时缩放,请使用:

Pixmap pixmap200 = new Pixmap(Gdx.files.internal("200x200.png"));
Pixmap pixmap100 = new Pixmap(100, 100, pixmap200.getFormat());
pixmap100.drawPixmap(pixmap200,
        0, 0, pixmap200.getWidth(), pixmap200.getHeight(),
        0, 0, pixmap100.getWidth(), pixmap100.getHeight()
);
Texture texture = new Texture(pixmap100);
pixmap200.dispose();
pixmap100.dispose();

从:

https://www.snip2code.com/Snippet/774713/LibGDX-Resize-texture-on-load

于 2016-07-14T19:08:32.653 回答
11
    batch.begin();
    batch.draw(yourtexture, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    batch.end();

使用相机视口也可以:

    batch.begin();
    batch.draw(yourtexture, 0, 0, cam.viewportWidth, cam.viewportHeight);
    batch.end();
于 2013-06-19T02:05:11.713 回答