38 lines
750 B
JavaScript
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);
|
|
}
|
|
}
|
|
|
|
}
|