-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame-object.js
More file actions
65 lines (50 loc) · 1.39 KB
/
game-object.js
File metadata and controls
65 lines (50 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class GameObject {
constructor() {
// Array of GameObjects
this._children = [];
// Array of GameComponents
this._components = [];
this._transform = new Transform();
this._engine = null;
}
addChild(child) {
this._children.push(child);
child.engine = this._engine;
child.transform.parent = this._transform;
}
addComponent(component) {
component.gameObject = this;
this._components.push(component);
}
updateAll() {
this.update();
for (var i = 0; i < this._children.length; i++) {
this._children[i].updateAll();
}
}
renderAll(renderingEngine) {
this.render(renderingEngine);
for (var i = 0; i < this._children.length; i++) {
this._children[i].renderAll(renderingEngine);
}
}
update() {
for (var i = 0; i < this._components.length; i++) {
this._components[i].update();
}
}
render(renderingEngine) {
for (var i = 0; i < this._components.length; i++) {
this._components[i].render(renderingEngine);
}
}
draw(count, offset) {
this._gl.drawElements(this._gl.TRIANGLES, count, this._gl.UNSIGNED_SHORT, offset);
}
get transform() {
return this._transform;
}
set engine(eng) {
this._engine = eng;
}
}