LibGDX TiledMap stuck to camera from Stage

196 views Asked by At

I have a screen with a Stage and a TiledMap. The map renders fine, but trying to move the camera won't do anything to the map. In the code below the camera is being moved to the right, and as a result the image goes left on the screen, but the map stays "glued" to the screen.

Before

About Half A Second Later

public class TestScreen implements Screen{
private Stage stage;

private TiledMap testMap;
private OrthogonalTiledMapRenderer mapRenderer;
private Image image;

public TestScreen() {
    stage = new Stage(new StretchViewport(GameBase.WIDTH, GameBase.HEIGHT));

    testMap = GameBase.assets.getLevel("level25");

    image = new Image(GameBase.assets.getTexture("sleuth"));
    stage.addActor(image);
    mapRenderer = new OrthogonalTiledMapRenderer(testMap, 1f);
    mapRenderer.setView(stage.getCamera().combined, 0, 0, GameBase.WIDTH, GameBase.HEIGHT);
    image.setOrigin(Align.center);
}

@Override
public void show() {    
    // TODO Auto-generated method stub

}

@Override
public void render(float delta) {
    image.rotateBy(2);

    stage.getCamera().position.x += 5;
    stage.getCamera().update();

    mapRenderer.render();
    stage.act(delta);
    stage.draw();
}

@Override
public void resize(int width, int height) {
    stage.getViewport().update(width, height, true);
}
1

There are 1 answers

0
JK Ly On BEST ANSWER

You have to call mapRenderer.setView(stage.getCamera()); on every frame to update the view on the tile map.