BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / window.js

window.js

remove outdated comments
timfa Tim Falken · pushed by timfa · 8 years ago
61a474fb History
window.js 2.1 KiB Download Raw
1
2
3var GameWindow =
4{
5
6 width: 0,
7
8 height: 0,
9
10 g_width: 0,
11 g_height: 0,
12
13 fullscreen: false,
14
15
16 backgroundColor:
17 {
18 r: 255,
19 g: 255,
20 b: 255
21 },
22
23 windowElement: null,
24 elementID: "GameBuilder_Window",
25
26 init: function(x, y, width, height)
27 {
28 GameWindow.x = x;
29 GameWindow.y = y;
30
31 GameWindow.width = width;
32 GameWindow.height = height;
33
34 GameWindow.g_width = width;
35 GameWindow.g_height = height;
36
37 var body = document.body;
38 body.insertAdjacentHTML('beforeend', '<canvas id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; border: 1px solid black;" width="' + GameWindow.width + '" height="' + GameWindow.height + '"></canvas>');
39
40 //$("body").append('<div id="' + GameWindow.elementID + '" style="position: absolute; left: ' + x + 'px; top: ' + y + 'px; width: ' + GameWindow.width + 'px; height: ' + GameWindow.height + 'px; overflow: hidden; border: 1px solid black;"></div>');
41 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
42
43
44 GameWindow.canvas = document.getElementById(GameWindow.elementID);
45
46
47 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
48
49 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
50 },
51
52 redraw: function()
53 {
54 TWEEN.update();
55
56 if(GameWindow.fullscreen)
57 {
58 GameWindow.width = window.innerWidth - 2;
59 GameWindow.height = window.innerHeight - 2;
60 }
61 else
62 {
63 GameWindow.width = GameWindow.g_width;
64 GameWindow.height = GameWindow.g_height;
65 }
66
67 GameWindow.canvas.width = GameWindow.width;
68 GameWindow.canvas.height = GameWindow.height;
69
70 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + this.backgroundColor.g + "," + this.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
71 this.canvasContext.fillRect(0, 0, this.width, this.height);
72
73 for(var i = 0; i < Game.activeScene.activeObjects.length; i++)
74 {
75 if(Game.activeScene.activeObjects[i].active && Game.activeScene.activeObjects[i].renderer.visible)
76 Game.activeScene.activeObjects[i].g_draw(GameWindow.canvasContext);
77 }
78 }
79}