From 044d8cc8cc4be52f3ad02b13927cebb40d375ea6 Mon Sep 17 00:00:00 2001 From: Eemeli Kelokorpi Date: Thu, 22 May 2014 10:07:03 +0300 Subject: [PATCH] Fixed resizeToFill Fixed engine starting when loading page at wrong orientation --- src/engine/core.js | 5 ++--- src/engine/loader.js | 3 +++ src/engine/system.js | 36 ++++++++++++++++++++---------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/engine/core.js b/src/engine/core.js index f7d690d4..074c1980 100644 --- a/src/engine/core.js +++ b/src/engine/core.js @@ -323,9 +323,8 @@ var core = { this.plugins[name] = new (this.plugins[name])(); } - this.loader = loaderClass || this.Loader; - var loader = new this.loader(window[this.System.startScene] || this[this.System.startScene] || scene); - loader.start(); + this.loader = new (loaderClass || this.Loader)(window[this.System.startScene] || this[this.System.startScene] || scene); + if (!this.system.rotateScreenVisible) this.loader.start(); }, loadScript: function(name, requiredFrom) { diff --git a/src/engine/loader.js b/src/engine/loader.js index 783eac7f..8ef055c6 100644 --- a/src/engine/loader.js +++ b/src/engine/loader.js @@ -45,6 +45,7 @@ game.Loader = game.Class.extend({ @property {Array} assets **/ sounds: [], + started: false, init: function(scene) { this.scene = scene || SceneGame; @@ -111,6 +112,8 @@ game.Loader = game.Class.extend({ @method start **/ start: function() { + this.started = true; + if (game.scene) { for (var i = this.stage.children.length - 1; i >= 0; i--) { this.stage.removeChild(this.stage.children[i]); diff --git a/src/engine/system.js b/src/engine/system.js index 3d8676df..1249acb2 100644 --- a/src/engine/system.js +++ b/src/engine/system.js @@ -90,19 +90,6 @@ game.System = game.Class.extend({ if (!width) width = (game.System.orientation === game.System.PORTRAIT ? 768 : 1024); if (!height) height = (game.System.orientation === game.System.PORTRAIT ? 927 : 672); - if (game.System.resizeToFill && game.device.mobile) { - var innerWidth = window.innerWidth; - var innerHeight = window.innerHeight; - - if (game.device.iPad && innerHeight === 671) innerHeight = 672; // iOS 7 bugfix - if (game.device.iPhone && innerHeight === 320) innerHeight = 319; // iOS 7 bugfix - - if (innerWidth / innerHeight !== width / height) { - if (game.System.orientation === game.System.LANDSCAPE) width = height * (innerWidth / innerHeight); - else height = width * (innerHeight / innerWidth); - } - } - if (game.System.hires) { if (typeof game.System.hiresWidth === 'number' && typeof game.System.hiresHeight === 'number') { if (window.innerWidth >= game.System.hiresWidth && window.innerHeight >= game.System.hiresHeight) { @@ -431,8 +418,25 @@ game.System = game.Class.extend({ var width = window.innerWidth; var height = window.innerHeight; - // iPad iOS 7.0 landscape innerHeight bugfix + // iOS 7 innerHeight bugfix if (game.device.iPad && height === 671 && this.orientation === game.System.LANDSCAPE) height = 672; + if (game.device.iPhone && height === 320 && this.orientation === game.System.LANDSCAPE) height = 319; + if (game.device.iPhone && height === 256 && this.orientation === game.System.LANDSCAPE) height = 319; + + if (game.System.resizeToFill && !this.rotateScreenVisible) { + if (width / height !== this.width / this.height) { + // Wrong ratio, need to resize + if (this.orientation === game.System.LANDSCAPE) { + this.width = this.height * (width / height); + this.ratio = this.width / this.height; + } + else { + this.height = this.width * (height / width); + this.ratio = this.height / this.width; + } + this.renderer.resize(this.width, this.height); + } + } if (game.System.orientation === game.System.LANDSCAPE) { this.canvas.style.height = height + 'px'; @@ -443,9 +447,9 @@ game.System = game.Class.extend({ this.canvas.style.height = width * this.ratio + 'px'; } - if (game.device.iOS71) setTimeout(this.onResize.bind(this), 100); - if (!game.device.ejecta) window.scroll(0, 1); + + if (!this.rotateScreenVisible && game.loader && !game.loader.started) game.loader.start(); } else { // Desktop resize