avocado-old/packages/graphics/container.js
2019-03-18 20:06:47 -05:00

38 lines
750 B
JavaScript

const PIXI = 'undefined' !== typeof window ? require('pixi.js') : undefined;
import {Renderable} from './renderable';
export class Container extends Renderable {
constructor() {
super();
this._children = [];
this.internal = PIXI ? new PIXI.Container() : undefined;
}
addChild(child) {
this._children.push(child);
this.internal.addChild(child.internal);
}
children() {
return this._children;
}
removeChild(child) {
const index = this._children.indexOf(child);
if (-1 === index) {
return;
}
this._children.splice(index, 1);
this.internal.removeChild(child.internal);
}
removeAllChildren() {
for (const child of this._children) {
this.removeChild(child);
}
}
}