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