Skip to content

Commit c884bab

Browse files
committed
Fixed instance check issue in Game and tidied up the stageScaleMode inner loop.
1 parent f76ba68 commit c884bab

6 files changed

Lines changed: 55 additions & 26 deletions

File tree

Phaser/Game.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ module Phaser {
3838
constructor(callbackContext, parent: string = '', width: number = 800, height: number = 600, preloadCallback = null, createCallback = null, updateCallback = null, renderCallback = null, destroyCallback = null) {
3939

4040
// Single instance check
41-
if (window['PhaserGlobal'].singleInstance)
41+
if (window['PhaserGlobal'] && window['PhaserGlobal'].singleInstance)
4242
{
4343
if (Phaser.GAMES.length > 0)
4444
{
45-
console.log('Phaser detected an instance of this game already running, aborting');
45+
throw new Error('Phaser detected an instance of this game already running, aborting');
4646
return;
4747
}
4848
}

Phaser/animation/Frame.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ module Phaser {
3838

3939
}
4040

41+
public game: Phaser.Game;
42+
4143
/**
4244
* X position within the image to cut from.
4345
* @type {number}

Phaser/loader/AnimationLoader.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,21 @@ module Phaser {
9595

9696
for (var i = 0; i < frames.length; i++)
9797
{
98-
newFrame = data.addFrame(new Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
99-
newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
98+
newFrame = data.addFrame(new Frame(
99+
frames[i].frame.x,
100+
frames[i].frame.y,
101+
frames[i].frame.w,
102+
frames[i].frame.h,
103+
frames[i].filename));
104+
105+
newFrame.setTrim(
106+
frames[i].trimmed,
107+
frames[i].sourceSize.w,
108+
frames[i].sourceSize.h,
109+
frames[i].spriteSourceSize.x,
110+
frames[i].spriteSourceSize.y,
111+
frames[i].spriteSourceSize.w,
112+
frames[i].spriteSourceSize.h);
100113
}
101114

102115
return data;

Phaser/system/StageScaleMode.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ module Phaser {
160160
public aspectRatio: number;
161161

162162
/**
163-
* The maximum number of times it will try to resize the canvas to fill the browser (default is 10)
163+
* The maximum number of times it will try to resize the canvas to fill the browser (default is 5)
164164
* @type {number}
165165
*/
166-
public maxIterations: number = 10;
166+
public maxIterations: number = 5;
167167

168168
/**
169169
* The scale factor of the scaled game width
@@ -247,6 +247,12 @@ module Phaser {
247247
*/
248248
public update() {
249249

250+
if (this.forceLandscape || this.forcePortrait)
251+
{
252+
this.checkOrientationState();
253+
}
254+
255+
/*
250256
if (this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height))
251257
{
252258
this.refresh();
@@ -256,6 +262,7 @@ module Phaser {
256262
{
257263
this.checkOrientationState();
258264
}
265+
*/
259266

260267
}
261268

Tests/phaser-debug.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5963,7 +5963,7 @@ var Phaser;
59635963
this.maxHeight = null;
59645964
this.width = 0;
59655965
this.height = 0;
5966-
this.maxIterations = 10;
5966+
this.maxIterations = 5;
59675967
this.game = game;
59685968
this.enterLandscape = new Phaser.Signal();
59695969
this.enterPortrait = new Phaser.Signal();
@@ -6025,9 +6025,6 @@ var Phaser;
60256025
}
60266026
};
60276027
StageScaleMode.prototype.update = function () {
6028-
if(this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height)) {
6029-
this.refresh();
6030-
}
60316028
if(this.forceLandscape || this.forcePortrait) {
60326029
this.checkOrientationState();
60336030
}
@@ -6934,7 +6931,6 @@ var Phaser;
69346931
this.delay = 1000 / frameRate;
69356932
}
69366933
if(loop !== null) {
6937-
console.log('play loop override', loop);
69386934
this.looped = loop;
69396935
}
69406936
this.isPlaying = true;
@@ -6966,9 +6962,7 @@ var Phaser;
69666962
this._frameIndex = 0;
69676963
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
69686964
this._parent.events.onAnimationLoop.dispatch(this._parent, this);
6969-
console.log('anim loop core');
69706965
} else {
6971-
console.log('anim complete core');
69726966
this.onComplete();
69736967
}
69746968
} else {
@@ -7059,7 +7053,7 @@ var Phaser;
70597053
};
70607054
AnimationManager.prototype.play = function (name, frameRate, loop) {
70617055
if (typeof frameRate === "undefined") { frameRate = null; }
7062-
if (typeof loop === "undefined") { loop = false; }
7056+
if (typeof loop === "undefined") { loop = null; }
70637057
if(this._anims[name]) {
70647058
if(this.currentAnim == this._anims[name]) {
70657059
if(this.currentAnim.isPlaying == false) {
@@ -7881,6 +7875,8 @@ var Phaser;
78817875
}
78827876
var width = img.width;
78837877
var height = img.height;
7878+
frameWidth *= game.stage.globalScale;
7879+
frameHeight *= game.stage.globalScale;
78847880
var row = Math.round(width / frameWidth);
78857881
var column = Math.round(height / frameHeight);
78867882
var total = row * column;
@@ -12658,14 +12654,21 @@ var Phaser;
1265812654
this._dw = sprite.crop.width * sprite.transform.scale.x;
1265912655
this._dh = sprite.crop.height * sprite.transform.scale.y;
1266012656
}
12661-
this._sx = Math.floor(this._sx);
12662-
this._sy = Math.floor(this._sy);
12663-
this._sw = Math.floor(this._sw);
12664-
this._sh = Math.floor(this._sh);
12665-
this._dx = Math.floor(this._dx);
12666-
this._dy = Math.floor(this._dy);
12667-
this._dw = Math.floor(this._dw);
12668-
this._dh = Math.floor(this._dh);
12657+
if(this.game.stage.globalScale != 1) {
12658+
this._sx = Math.floor(this._sx * this.game.stage.globalScale);
12659+
this._sy = Math.floor(this._sy * this.game.stage.globalScale);
12660+
this._dx = Math.floor(this._dx * this.game.stage.globalScale);
12661+
this._dy = Math.floor(this._dy * this.game.stage.globalScale);
12662+
} else {
12663+
this._sx = Math.floor(this._sx);
12664+
this._sy = Math.floor(this._sy);
12665+
this._sw = Math.floor(this._sw);
12666+
this._sh = Math.floor(this._sh);
12667+
this._dx = Math.floor(this._dx);
12668+
this._dy = Math.floor(this._dy);
12669+
this._dw = Math.floor(this._dw);
12670+
this._dh = Math.floor(this._dh);
12671+
}
1266912672
if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
1267012673
return false;
1267112674
}
@@ -13984,6 +13987,7 @@ var Phaser;
1398413987
var Stage = (function () {
1398513988
function Stage(game, parent, width, height) {
1398613989
var _this = this;
13990+
this.globalScale = 1;
1398713991
this._backgroundColor = 'rgb(0,0,0)';
1398813992
this.clear = true;
1398913993
this.disablePauseScreen = false;
@@ -14259,6 +14263,12 @@ var Phaser;
1425914263
this.onDestroyCallback = null;
1426014264
this.isBooted = false;
1426114265
this.isRunning = false;
14266+
if(window['PhaserGlobal'].singleInstance) {
14267+
if(Phaser.GAMES.length > 0) {
14268+
console.log('Phaser detected an instance of this game already running, aborting');
14269+
return;
14270+
}
14271+
}
1426214272
this.id = Phaser.GAMES.push(this) - 1;
1426314273
this.callbackContext = callbackContext;
1426414274
this.onPreloadCallback = preloadCallback;

build/phaser-debug.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5963,7 +5963,7 @@ var Phaser;
59635963
this.maxHeight = null;
59645964
this.width = 0;
59655965
this.height = 0;
5966-
this.maxIterations = 10;
5966+
this.maxIterations = 5;
59675967
this.game = game;
59685968
this.enterLandscape = new Phaser.Signal();
59695969
this.enterPortrait = new Phaser.Signal();
@@ -6025,9 +6025,6 @@ var Phaser;
60256025
}
60266026
};
60276027
StageScaleMode.prototype.update = function () {
6028-
if(this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height)) {
6029-
this.refresh();
6030-
}
60316028
if(this.forceLandscape || this.forcePortrait) {
60326029
this.checkOrientationState();
60336030
}

0 commit comments

Comments
 (0)