1
votes

In my LibGdx game I have it using a ExtendedViewport

 new ExtendViewport(LevelSmash.WIDTH, LevelSmash.HEIGHT, camera);

I set a width of 708, and height of 900,

In my render method i scale the spritebatch to the projection of the viewport

    @Override
public void render(SpriteBatch sb) {

    sb.setProjectionMatrix(vp.getCamera().projection);

    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

    sb.begin();
    level.render(sb);
    sb.end();

    stage.act();
    stage.draw();
}

The level's render method is

    @Override
public void render(SpriteBatch sb) {
    sb.setProjectionMatrix(vp.getCamera().projection);
    sb.draw(background, 0 / LevelSmash.PPM, 0 / LevelSmash.PPM);

    player.draw(sb);
}

PPM is equal to 100

I want the background to take the whole screen since its the width and height i scaled everything to (708, 900)

But it looks like this

enter image description here

1

1 Answers

2
votes

Looks like your camera is centered on 0, 0 and your texture starts drawing at 0, 0 to 708, 900. Best to set your camera's center to the center of the image.

camera.position.set(LevelSmash.WIDTH / 2, LevelSmash.HEIGHT / 2);
camera.update();

EDIT

I find it strange that the brackground is being drawn at all.

sb.draw(background, 0 / LevelSmash.PPM, 0 / LevelSmash.PPM);
// 0 / X == 0 so width and height are always 0;

Can you explain this? Since it's hard to believe you see anything being drawn by that line.