When I was creating my first tiled map creator in libGDX
, I noticed a very strange bug. I creating grid of objects like this:
private static final i
The camera is correct. The problem is the batch.begin()
and batch.end()
. As you might know you cannot do batch.begin()
and then shaperenderer.begin()
directly after each others without closing one of them. Reason for this I am not 100% about. stage
works similar. This means we have to close the batch before drawing the stage
batch.end();
stage.draw();
batch.begin();
// draw your batch stuff here
Also it's terrible to do this
batch = new SpriteBatch();
camera=new OrthographicCamera(CAM_WIDTH,CAM_HEIGHT);
inside the render method. Instead, put it into the create()
method or some of your own initialize method. The important thing is to not create a new SpriteBatch every frame as the batch isn't collected by the GC. So you have to manually dispose it using batch.dispose()
or it will leak so much memory your RAM will be gone in no time.
I hope this helped you out, good luck.