Skip to content

Commit

Permalink
Fixed resizeToFill
Browse files Browse the repository at this point in the history
Fixed engine starting when loading page at wrong orientation
  • Loading branch information
Eemeli Kelokorpi committed May 22, 2014
1 parent abbe65b commit 044d8cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/engine/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/engine/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ game.Loader = game.Class.extend({
@property {Array} assets
**/
sounds: [],
started: false,

init: function(scene) {
this.scene = scene || SceneGame;
Expand Down Expand Up @@ -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]);
Expand Down
36 changes: 20 additions & 16 deletions src/engine/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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';
Expand All @@ -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
Expand Down

0 comments on commit 044d8cc

Please sign in to comment.