问题
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