class Scene { static idCount = 0; activeObjects = []; position = new vector(0, 0); size = new vector(0, 0); cameraPosition = new vector(0, 0); parentScene = null; fullscreen = false; cv_canvas = null; cv_context = null; constructor(x, y, width, height, fullscreen = false) { Scene.idCount++; this.position.x = x; this.position.y = y; this.size.x = width; this.size.y = height; this.fullscreen = fullscreen; let body = document.body; body.insertAdjacentHTML('beforeend', ''); this.cv_canvas = document.getElementById('canvas_' + Scene.idCount); this.cv_canvasContext = this.cv_canvas.getContext('2d'); } backgroundColor = { r: 255, g: 255, b: 255 } get canvas() { return this.canvas; } get context() { return this.canvasContext; } addObject(obj) { this.activeObjects.push(obj); } destroy() { for(var i = 0; i < this.activeObjects.length; i++) { this.activeObjects[i].destroy(); } } redraw() { if(this.fullscreen) { this.size.width = window.innerWidth - 2; this.size.height = window.innerHeight - 2; } this.canvas.width = this.size.width; this.canvas.height = this.size.height; this.canvasContext.fillStyle = "rgb(" + this.backgroundColor.r + "," + GameWindow.backgroundColor.g + "," + GameWindow.backgroundColor.b + ")"; // sets the color to fill in the rectangle with this.canvasContext.fillRect(0, 0, this.size.width, this.size.height); for(var i = 0; i < this.activeObjects.length; i++) { if(this.activeObjects[i].active && this.activeObjects[i].renderer.visible) this.activeObjects[i].g_draw(this.canvasContext); } //requestAnimationFrame(GameWindow.redraw); // <- This must be called in global game update loop! } }