Created
November 12, 2016 09:35
-
-
Save raduGaspar/8aa07bc422826c670f93ee77d2d54848 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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