虽然经历了Stage的libgdx源代码中的本地参考,我遇到了这个段:的Java在实例变量
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();
}
我的是什么兴趣这一行:Batch batch = this.batch;
我的第一个猜测是一些缓存改进。我是对的,还是有其他原因避免直接使用实例变量?
你是否已经开始使用调试器?猜测,也许在身体递归(并修改实例'批次'参考)的东西。 – 2015-02-06 02:10:25
另请参见[“避免getfield操作码”](http://stackoverflow.com/questions/4761681/avoiding-getfield-opcode)。 – Radiodef 2015-02-06 02:59:58
好的想法,但批处理实例引用在'begin()'和'end()'块之间没有改变,并且这种绘制方法不是递归的。 – EntangledLoops 2015-02-06 03:16:16