BlueGit

timfa frameworkv3

Files

frameworkv3 / framework / window.js

window.js

Framework 3
timfa Tim Falken · pushed by timfa · 9 years ago
4a56d325 History
window.js 2.1 KiB Download Raw
1//<DOC> category GameWindow
2
3var GameWindow =
4{
5 //<DOC> <parameter> GameWindow.width<br>The game window's width. Cannot be changed.
6 width: 0,
7 //<DOC> <parameter> GameWindow.height<br>The game window's height. Cannot be changed.
8 height: 0,
9
10 //<DOC> <parameter> GameWindow.backgroundColor<br>Background color. Contains an r, g and b component (0-255).
11 backgroundColor:
12 {
13 r: 255,
14 g: 255,
15 b: 255
16 },
17
18 windowElement: null,
19 elementID: "GameBuilder_Window",
20
21 init: function(x, y, width, height)
22 {
23 GameWindow.x = x;
24 GameWindow.y = y;
25
26 GameWindow.width = width;
27 GameWindow.height = height;
28
29 var body = document.body;
30 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>');
31
32 //$("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>');
33 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
34
35 //<DOC> <parameter> GameWindow.canvas <br><br> The game's canvas element
36 GameWindow.canvas = document.getElementById(GameWindow.elementID);
37
38 //<DOC> <parameter> GameWindow.canvasContext <br><br>The game's canvasContext. Use this for drawing.
39 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
40
41 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
42 },
43
44 redraw: function()
45 {
46 TWEEN.update();
47
48 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + this.backgroundColor.g + "," + this.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
49 this.canvasContext.fillRect(0, 0, this.width, this.height);
50
51 for(var i = 0; i < Game.activeObjects.length; i++)
52 {
53 if(Game.activeObjects[i].active && Game.activeObjects[i].renderer.visible)
54 Game.activeObjects[i].g_draw(GameWindow.canvasContext);
55 }
56 }
57}