While going through the libgdx source code for a Stage, I encountered this segment:
public void draw () {
Camera camera = viewport.getCamera();
camera.update();
if (!root.isVisible()) return;
Batch batch = this.batch;
if (batch != null) {
batch.setProjectionMatrix(camera.combined);
batch.begin();
root.draw(batch, 1);
batch.end();
}
if (debug) drawDebug();
}
What interested me was this line: Batch batch = this.batch;
My first guess was some caching improvement. Am I right, or is there another reason to avoid using the instance variable directly?