12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- class GameObject
- {
- constructor(name)
- {
- this.id = 0;
- this.name = name;
- this.children = [];
- this.parented = false;
- this.parent = null;
- GameHandler.instanceGameObject(this);
- }
-
- getChildren()
- {
- return this.children;
- }
- getChildByIndex(idx)
- {
- if (idx >= 0 && idx < this.children.length)
- return this.children[idx];
- return null;
- }
- getChildByName(name)
- {
- for (let i = 0; i < this.children.length; i++)
- if (this.children[i].name == name) return this.children[i];
- return null;
- }
- getParent()
- {
- if (!this.parented) return null;
- return this.parent;
- }
-
- addChild(child)
- {
- child.parent = this;
- child.parented = true;
- this.children.push(child);
- }
- update(delta)
- {
- this._update(delta);
- for (let i = 0; i < this.children.length; i++)
- this.children[i].update(delta);
- }
- draw(delta)
- {
- this._draw(delta);
- for (let i = 0; i < this.children.length; i++)
- this.children[i].draw(delta);
- }
-
- _update(delta)
- {
- }
- _draw(delta)
- {
- }
- }
|