Libgdx相机/缩放问题

时间:2015-05-13 15:12:25

标签: java camera libgdx scaling aspect-ratio

这只是一个非常快速的帖子,想知道我做错了什么?

我希望在整个屏幕上使用我拥有的任何屏幕尺寸填充背景但这不会使其工作。 This is the result when i run the program以下是所有代码:

// Variables

Jump game;

OrthographicCamera cam;

SpriteBatch sb;

 // Variables

public SplashScreen(Jump game)
{
    this.game = game;

    cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    cam.translate(cam.viewportWidth / 2, cam.viewportHeight / 2);

    sb = new SpriteBatch();
}

public void show() 
{

}

public void render(float delta) 
{
    Gdx.gl20.glClearColor(0.2F, 0.6F, 1F, 1F);

    Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);

    cam.update();

    sb.begin();

    sb.setProjectionMatrix(cam.combined);

    sb.draw(Assets.splash_spr_background, 0, 0);

    sb.end();

}

谢谢! :)

1 个答案:

答案 0 :(得分:3)

问题是您的资产与视口的大小不同。请参阅以下链接。 Libgdx使用Viewport类来处理这个问题。

How to deal with different aspect ratios in libGDX?

How to scale image according to different screen resolutions in libgdx

https://github.com/libgdx/libgdx/wiki/Viewports