opt: only sort container when necessary

This commit is contained in:
cha0s 2019-04-28 07:31:44 -05:00
parent ca28e52231
commit 6e5d5384e1

View File

@ -103,15 +103,22 @@ export class Container extends Renderable {
}
renderTick(elapsed) {
let needsSort = false;
for (const child of this._children) {
if (0 !== child.zIndex) {
needsSort = true;
}
for (let i = 0; i < this._children.length; i++) {
const child = this._children[i];
if (child instanceof Container) {
child.renderTick(elapsed);
}
}
let needsSort = false;
let currentZ = -Infinity;
for (let i = 0; i < this._children.length; i++) {
const child = this._children[i];
if (currentZ > child.zIndex) {
needsSort = true;
break;
}
currentZ = child.zIndex;
}
if (!needsSort) {
return;
}