0
\$\begingroup\$

I'm using LibGDX and Tiled. I need to render a Texture for my repeated background, then myTiled map and finally the sprites.

My problem is that if I put mapRenderer.render() between batch.begin() and batch.end(), the background texture is not being rendered. If I render the map before or afterthe batch, some objects are hided.

So the logic of what I want to do is:

public void render(float delta) {
  // update

  // clear screen

  batch.begin();

  // draw repeated background texture

  // draw map
  mapRenderer.setView(camera);
  mapRenderer.render();

  // draw sprites

  batch.end();
}

Any idea what I might be missing and how to fix it?

Edit

Followup question, to make sure that what I'm asking is valid. I was under the impression that calling batch.begin() and batch.end() multiple times was inefficient. But from what I've been searching it seems that it's not. I was confusing it with creating more than one SpriteBatch. So I guess it's fine to do more then one begin/end call in each frame? Sorry if my question is trivial, but I'm new to LibGDX.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

In this case, there is no other solution than to call it multiple times. That is, to render your background, the map, and the sprites.

I assume all of them have different textures anyway, so there won't be any performance difference.

batch.begin();
// draw repeated background texture
batch.end();

// draw map
mapRenderer.setView(camera);
mapRenderer.render();

batch.begin();
// draw sprites
batch.end();
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .