From de0cad37abbef27228feb95384116c3770ab9355 Mon Sep 17 00:00:00 2001 From: -=yb4f310 Date: Sun, 14 Jan 2018 15:37:32 +0100 Subject: [PATCH] update camera aspect ratios when renderer size updates --- src/game-lib-a-component-a.js | 2 +- src/game-lib-d3-renderer.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 39a4eef..f4e6d8c 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -990,7 +990,7 @@ GameLib.Component.prototype.generateNewIds = function() { this.idToObject[property].id = newId; this.idToObject[property].name = this.idToObject[property].name.replace(oldId,newId); - // TODO: replace image filenames - but then also copy them server side? + // TODO: replace image filenames - but then also copy them server side? // if (this.idToObject[property].fileName) { // this.idToObject[property].fileName = this.idToObject[property].fileName.replace(oldId,newId); // } diff --git a/src/game-lib-d3-renderer.js b/src/game-lib-d3-renderer.js index 5312684..5942e19 100644 --- a/src/game-lib-d3-renderer.js +++ b/src/game-lib-d3-renderer.js @@ -279,20 +279,34 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) { if (property === 'width') { trueWidth = this.width * this.windowSize.x; + trueHeight = this.height * this.windowSize.y; this.canvas.width = trueWidth; this.canvas.updateInstance('width'); + this.camera.aspect = trueWidth / trueHeight; + this.camera.updateInstance('aspect'); + + this.editCamera.aspect = trueWidth / trueHeight; + this.editCamera.updateInstance('aspect'); + this.instance.setSize(trueWidth, this.height * this.windowSize.y); } if (property === 'height') { + trueWidth = this.width * this.windowSize.x; trueHeight = this.height * this.windowSize.y; this.canvas.height = trueHeight; this.canvas.updateInstance('height'); + this.camera.aspect = trueWidth / trueHeight; + this.camera.updateInstance('aspect'); + + this.editCamera.aspect = trueWidth / trueHeight; + this.editCamera.updateInstance('aspect'); + this.instance.setSize(this.width * this.windowSize.x, trueHeight); } @@ -307,6 +321,12 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) { this.canvas.updateInstance('width'); this.canvas.updateInstance('height'); + this.camera.aspect = trueWidth / trueHeight; + this.camera.updateInstance('aspect'); + + this.editCamera.aspect = trueWidth / trueHeight; + this.editCamera.updateInstance('aspect'); + this.instance.setSize(trueWidth, trueHeight); } @@ -446,6 +466,12 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) { this.canvas.instance.style.left = (this.offset.x * this.windowSize.x) + 'px'; this.canvas.instance.style.top = (this.offset.y * this.windowSize.y) + 'px'; + + this.camera.aspect = trueWidth / trueHeight; + this.camera.updateInstance('aspect'); + + this.editCamera.aspect = trueWidth / trueHeight; + this.editCamera.updateInstance('aspect'); } if (property === 'offset') {