Skip to content

Instantly share code, notes, and snippets.

@raduGaspar
Created November 12, 2016 09:35
Show Gist options
  • Save raduGaspar/8aa07bc422826c670f93ee77d2d54848 to your computer and use it in GitHub Desktop.
Save raduGaspar/8aa07bc422826c670f93ee77d2d54848 to your computer and use it in GitHub Desktop.
import Scene from './Scene';
export default class DisplayObject extends Scene {
constructor() {
super();
this.children = [];
}
add(elem) {
if(elem.constructor === Array) {
for(let el of elem) {
el.scene = this.scene;
this.children.push(el);
}
} else {
elem.scene = this.scene;
this.children.push(elem);
}
}
remove(elem) {
let idx = this.children.indexOf(elem);
if(idx > -1) {
this.children.splice(idx, 1);
}
}
update() {
for(let el of this.children) {
if(typeof el.update === 'function') {
el.update();
}
if(typeof el.render === 'function') {
el.render();
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment