BlueGit

timfa frameworkv3

Files

frameworkv3 / window.js

window.js

window.js 2.0 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.width = width;
24 GameWindow.height = height;
25
26 var body = document.body;
27 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>');
28
29 //$("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>');
30 GameWindow.windowElement = document.getElementById(GameWindow.elementID);
31
32 //<DOC> <parameter> GameWindow.canvas <br><br> The game's canvas element
33 GameWindow.canvas = document.getElementById(GameWindow.elementID);
34 //<DOC> <parameter> GameWindow.canvasContext <br><br>The game's canvasContext. Use this for drawing.
35 GameWindow.canvasContext = GameWindow.canvas.getContext('2d');
36
37 console.log("GAME: Window initialized: [" + width + ", " + height + "]");
38 },
39
40 redraw: function()
41 {
42 this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + this.backgroundColor.g + "," + this.backgroundColor.b + ")"; // sets the color to fill in the rectangle with
43 this.canvasContext.fillRect(0, 0, this.width, this.height);
44
45 for(var i = 0; i < Game.activeObjects.length; i++)
46 {
47 if(Game.activeObjects[i].active && Game.activeObjects[i].renderer.visible)
48 Game.activeObjects[i].g_draw(GameWindow.canvasContext);
49 }
50 }
51}