35 var sceneBgColor = opts.sceneBgColor; |
35 var sceneBgColor = opts.sceneBgColor; |
36 var sceneWidth = opts.sceneWidth; |
36 var sceneWidth = opts.sceneWidth; |
37 var sceneHeight = opts.sceneHeight; |
37 var sceneHeight = opts.sceneHeight; |
38 var canvasContainer = opts.canvasContainer; |
38 var canvasContainer = opts.canvasContainer; |
39 var timeContainer = []; |
39 var timeContainer = []; |
40 var components = []; |
40 var components = []; |
41 |
41 |
42 //create an new instance of a pixi stage |
42 //create an new instance of a pixi stage |
43 this.stage = new PIXI.Stage(sceneBgColor); |
43 this.stage = new PIXI.Stage(sceneBgColor); |
44 //create a renderer instance. |
44 //create a renderer instance. |
45 var renderer = PIXI.autoDetectRenderer(sceneWidth, sceneHeight); |
45 var renderer = PIXI.autoDetectRenderer(sceneWidth, sceneHeight); |
46 |
46 |
47 this.init = function() { |
47 this.init = function() { |
48 |
48 |
49 if(typeof(canvasContainer) === 'string') { |
49 if(typeof(canvasContainer) === 'string') { |
50 canvasContainer = document.getElementById(canvasContainer); |
50 canvasContainer = document.getElementById(canvasContainer); |
51 } |
51 } |
52 if(typeof(timeContainer) === 'string') { |
52 if(typeof(timeContainer) === 'string') { |
53 timeContainer = document.getElementById(timeContainer); |
53 timeContainer = document.getElementById(timeContainer); |
54 } |
54 } |
55 |
55 |
56 canvasContainer.appendChild(renderer.view); |
56 canvasContainer.appendChild(renderer.view); |
57 |
57 |
58 components.forEach(function(c){ |
58 components.forEach(function(c){ |
59 c.init(); |
59 c.init(); |
60 }); |
60 }); |
61 }; |
61 }; |
62 |
62 |
63 this.registerTimeContainer = function(container) { |
63 this.registerTimeContainer = function(container) { |
64 timeContainer.push(container); |
64 timeContainer.push(container); |
65 }; |
65 }; |
66 |
66 |
67 this.registerComponent = function(component) { |
67 this.registerComponent = function(component) { |
68 components.push(component); |
68 components.push(component); |
69 this.stage.addChild(component.container); |
69 this.stage.addChild(component.container); |
70 }; |
70 }; |
71 |
71 |
82 this.start = function() { |
82 this.start = function() { |
83 |
83 |
84 if(!externalRefresh) { |
84 if(!externalRefresh) { |
85 refreshInterval = setInterval(function() {_this.refresh();}, 1000/this.framerate); |
85 refreshInterval = setInterval(function() {_this.refresh();}, 1000/this.framerate); |
86 } |
86 } |
87 |
87 |
88 components.forEach(function(c){ |
88 components.forEach(function(c){ |
89 c.start(); |
89 c.start(); |
90 }); |
90 }); |
91 }; |
91 }; |
92 |
92 |
93 this.stop = function() { |
93 this.stop = function() { |
94 if(!externalRefresh) { |
94 if(!externalRefresh) { |
95 clearInterval(refreshInterval); |
95 clearInterval(refreshInterval); |
96 } |
96 } |
97 clearInterval(refreshTimeInterval); |
|
98 |
97 |
99 components.forEach(function(c){ |
98 components.forEach(function(c){ |
100 c.stop(); |
99 c.stop(); |
101 }); |
100 }); |
102 }; |
101 }; |