简体   繁体   English

在libgdx中拉伸/压缩图像

[英]Stretching/compressing images in libgdx

我一直在尝试使图像按分辨率缩放,但是我找不到将其压缩到设定的宽度和高度的简便方法。

Here what i use : 这是我使用的:

public static float xTrans(float x)
{
    return x*Gdx.graphics.getWidth()/SCREEN_WIDTH;
}

public static float yTrans(float y)
{
    return y*Gdx.graphics.getHeight()/SCREEN_HEIGHT;
}

Gdx.graphics.getHeight() : is the current screen height of the device Gdx.graphics.getHeight() :是设备的当前屏幕高度

Gdx.graphics.getwidth() : is the current screen width of the device Gdx.graphics.getwidth() :是设备的当前屏幕宽度

SCREEN_WIDTH is the width screen reference : I put it to (480) SCREEN_WIDTH是屏幕的宽度参考:我将其设置为(480)

SCREEN_HEIGHT is the height screen reference : I put it to (320) SCREEN_HEIGHT是屏幕的高度参考:我将其设置为(320)

example of use 使用实例

yourSprite.setSize(xTrans(20),yTrans(15));

also you could put diferent size of the same image resource and load them depending on the size resolution of your screen 您还可以将不同大小的相同图像资源放入并加载它们,具体取决于屏幕的尺寸分辨率

hope that was helpfull 希望对您有所帮助

good luck 祝好运

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

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