| 1 | |
| 2 | |
| 3 | var GameWindow = |
| 4 | { |
| 5 | |
| 6 | width: 0, |
| 7 | |
| 8 | height: 0, |
| 9 | |
| 10 | g_width: 0, |
| 11 | g_height: 0, |
| 12 | |
| 13 | cameraPosition: new vector(0, 0), |
| 14 | |
| 15 | fullscreen: false, |
| 16 | |
| 17 | |
| 18 | backgroundColor: |
| 19 | { |
| 20 | r: 255, |
| 21 | g: 255, |
| 22 | b: 255 |
| 23 | }, |
| 24 | |
| 25 | windowElement: null, |
| 26 | elementID: "GameBuilder_Window", |
| 27 | |
| 28 | init: function(x, y, width, height) |
| 29 | { |
| 30 | GameWindow.x = x; |
| 31 | GameWindow.y = y; |
| 32 | |
| 33 | GameWindow.width = width; |
| 34 | GameWindow.height = height; |
| 35 | |
| 36 | GameWindow.g_width = width; |
| 37 | GameWindow.g_height = height; |
| 38 | |
| 39 | var body = document.body; |
| 40 | 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>'); |
| 41 | |
| 42 | //$("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>'); |
| 43 | GameWindow.windowElement = document.getElementById(GameWindow.elementID); |
| 44 | |
| 45 | GameWindow.canvas = document.getElementById(GameWindow.elementID); |
| 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 | } |