-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraphicManager.js
55 lines (47 loc) · 1.54 KB
/
GraphicManager.js
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
(function() {
// This manages all the graphics inside it
function GraphicManager() {
this.graphics = [];
}
function isGraphic(obj) {
if(obj instanceof Game.Graphic) {
return true;
}
return false
}
GraphicManager.prototype.constructor = GraphicManager;
// If a the object passed is not a graphic make a new Graphic from that object or error out
GraphicManager.prototype.add = function(graphic) {
if(isGraphic(graphic)) {
this.graphics.push(graphic);
} else if(typeof graphic === "object") {
var newGraphic = new Game.Graphic(graphic);
this.graphics.push(newGraphic);
} else {
throw new Error("Paramater was not Game.Graphic or graphic property object.");
}
}
// Loop through and update all the visible graphics on the screen - performance
GraphicManager.prototype.updateGraphics = function() {
for(var i = 0; i < this.graphics.length; i++) {
if(this.graphics[i].isVisible) {
this.graphics[i].update()
}
}
}
// Loop through and render all the visible graphics on the screen - performance
// If it is not fixed render by the given offsets
GraphicManager.prototype.renderGraphics = function(xView, yView) {
for(var i = 0; i < this.graphics.length; i++) {
if(this.graphics[i].isVisible) {
if(this.graphics[i].isFixed) {
this.graphics[i].render();
} else {
this.graphics[i].render(xView, yView);
}
}
}
};
// Add GraphicManager to the Game
Game.GraphicManager = GraphicManager;
})();