Skip to content Skip to sidebar Skip to footer

Orthogonaltiledmaprenderer And Normal Spritebatch Renders A White Box?

I am using Libgdx to render a TileMap as a background of my game. I might render some different layers later on. Without the tilemap render and a single background picture it works

Solution 1:

Many of the Libgdx render helper objects assume they "own" the state in the OpenGL runtime, so the output gets confused if you have two of them making changes to OpenGL at the same time. In your case the OrthogonalTiledMapRenderer has its own SpriteBatch, so you have two SpriteBatch (silently) fighting each other.

Try changing your Map.render() method to end the in-progress SpriteBatch before rendering the map (and then restart it afterwards):

@Override
public void draw(SpriteBatch batch, float parentAlpha) {
  batch.end();
  this.render.setView((OrthographicCamera) this.getStage().getCamera());
  render.render();
  batch.begin();
}

If that helps, you might look at setting up your tile map to "share" the same SpriteBatch as the rest of your code (as these are somewhat heavy objects). That should be more efficient and should remove the need to end/start the SpriteBatch.

Solution 2:

I had a similar issue where I was using a batch to first draw a tilemap, then my own textures. It drew white rectangles at exactly the right size and position as the texture.

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    mapRenderer.render();
    GameObjectSystem.inst().render(RenderLayer.floor, batch);
    GameObjectSystem.inst().render(RenderLayer.ground, batch);
    batch.end();

Ending the batch after drawing the tilemap and restarting it fixed the problem.

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    mapRenderer.render();
    batch.end();

    batch.begin();
    GameObjectSystem.inst().render(RenderLayer.floor, batch);
    GameObjectSystem.inst().render(RenderLayer.ground, batch);
    batch.end();

Post a Comment for "Orthogonaltiledmaprenderer And Normal Spritebatch Renders A White Box?"