Libgdx camera/scaling issue

隐身守侯 提交于 2020-01-11 12:50:31

问题


This is just a really quick post wondering what i have done wrong?

I want the background to be filled on the whole screen with whatever screen sizes i have but this does not make it work.

Here is all the code:
// 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();

}

Thanks! :)


回答1:


The problem is your asset is not the same size as the viewport. See the links below. Libgdx uses the Viewport class to handle this.

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



来源:https://stackoverflow.com/questions/30218900/libgdx-camera-scaling-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!