Reputation: 329
I am learning LibGDX using Tiled Map. I came across the following two render methods. The first one is simple one that I normally use.
However, I don't understand why we need the second one. Can I use batch.begin(); in method2 as well.
Thanks
Method 1
private Batch batch;
batch=new SpriteBatch();
public void Render(float delta){
......
batch.begin();
batch.draw(......);
batch.end();
}
Method 2
private OrthogonalTiledMapRenderer renderer;
private Batch batch;
public void Render(float delta){
......
renderer.getBatch().begin();
renderer.getBatch().draw(......);
renderer.getBatch().end();
}
Upvotes: 2
Views: 534
Reputation: 19776
It's pretty much the same. Here you can see that in case you do not supply a Batch
to the renderer, it will create a new Spritebatch()
itself. You can, however, also supply your own Batch
to the renderer.
The OrthogonalTiledMapRenderer extends BatchTiledMapRenderer
, which will call Batch.begin()
and end()
itself, so you do not have to care about that.
Upvotes: 1