From c884bab7ec240c9cab79eda4d14bb174cbeb91eb Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Fri, 16 Aug 2013 02:18:12 +0100 Subject: [PATCH] Fixed instance check issue in Game and tidied up the stageScaleMode inner loop. --- Phaser/Game.ts | 4 +-- Phaser/animation/Frame.ts | 2 ++ Phaser/loader/AnimationLoader.ts | 17 +++++++++++-- Phaser/system/StageScaleMode.ts | 11 +++++++-- Tests/phaser-debug.js | 42 ++++++++++++++++++++------------ build/phaser-debug.js | 5 +--- 6 files changed, 55 insertions(+), 26 deletions(-) diff --git a/Phaser/Game.ts b/Phaser/Game.ts index 1dbd01dc..d01ba9b8 100644 --- a/Phaser/Game.ts +++ b/Phaser/Game.ts @@ -38,11 +38,11 @@ module Phaser { constructor(callbackContext, parent: string = '', width: number = 800, height: number = 600, preloadCallback = null, createCallback = null, updateCallback = null, renderCallback = null, destroyCallback = null) { // Single instance check - if (window['PhaserGlobal'].singleInstance) + if (window['PhaserGlobal'] && window['PhaserGlobal'].singleInstance) { if (Phaser.GAMES.length > 0) { - console.log('Phaser detected an instance of this game already running, aborting'); + throw new Error('Phaser detected an instance of this game already running, aborting'); return; } } diff --git a/Phaser/animation/Frame.ts b/Phaser/animation/Frame.ts index aefe19ec..d00f47fd 100644 --- a/Phaser/animation/Frame.ts +++ b/Phaser/animation/Frame.ts @@ -38,6 +38,8 @@ module Phaser { } + public game: Phaser.Game; + /** * X position within the image to cut from. * @type {number} diff --git a/Phaser/loader/AnimationLoader.ts b/Phaser/loader/AnimationLoader.ts index 8bb31214..cb08c032 100644 --- a/Phaser/loader/AnimationLoader.ts +++ b/Phaser/loader/AnimationLoader.ts @@ -95,8 +95,21 @@ module Phaser { for (var i = 0; i < frames.length; i++) { - newFrame = data.addFrame(new Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename)); - 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); + newFrame = data.addFrame(new Frame( + frames[i].frame.x, + frames[i].frame.y, + frames[i].frame.w, + frames[i].frame.h, + frames[i].filename)); + + 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); } return data; diff --git a/Phaser/system/StageScaleMode.ts b/Phaser/system/StageScaleMode.ts index 549b3718..c2a968a4 100644 --- a/Phaser/system/StageScaleMode.ts +++ b/Phaser/system/StageScaleMode.ts @@ -160,10 +160,10 @@ module Phaser { public aspectRatio: number; /** - * The maximum number of times it will try to resize the canvas to fill the browser (default is 10) + * The maximum number of times it will try to resize the canvas to fill the browser (default is 5) * @type {number} */ - public maxIterations: number = 10; + public maxIterations: number = 5; /** * The scale factor of the scaled game width @@ -247,6 +247,12 @@ module Phaser { */ public update() { + if (this.forceLandscape || this.forcePortrait) + { + this.checkOrientationState(); + } + + /* if (this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height)) { this.refresh(); @@ -256,6 +262,7 @@ module Phaser { { this.checkOrientationState(); } + */ } diff --git a/Tests/phaser-debug.js b/Tests/phaser-debug.js index 20c6e31c..2b141b0b 100644 --- a/Tests/phaser-debug.js +++ b/Tests/phaser-debug.js @@ -5963,7 +5963,7 @@ var Phaser; this.maxHeight = null; this.width = 0; this.height = 0; - this.maxIterations = 10; + this.maxIterations = 5; this.game = game; this.enterLandscape = new Phaser.Signal(); this.enterPortrait = new Phaser.Signal(); @@ -6025,9 +6025,6 @@ var Phaser; } }; StageScaleMode.prototype.update = function () { - if(this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height)) { - this.refresh(); - } if(this.forceLandscape || this.forcePortrait) { this.checkOrientationState(); } @@ -6934,7 +6931,6 @@ var Phaser; this.delay = 1000 / frameRate; } if(loop !== null) { - console.log('play loop override', loop); this.looped = loop; } this.isPlaying = true; @@ -6966,9 +6962,7 @@ var Phaser; this._frameIndex = 0; this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); this._parent.events.onAnimationLoop.dispatch(this._parent, this); - console.log('anim loop core'); } else { - console.log('anim complete core'); this.onComplete(); } } else { @@ -7059,7 +7053,7 @@ var Phaser; }; AnimationManager.prototype.play = function (name, frameRate, loop) { if (typeof frameRate === "undefined") { frameRate = null; } - if (typeof loop === "undefined") { loop = false; } + if (typeof loop === "undefined") { loop = null; } if(this._anims[name]) { if(this.currentAnim == this._anims[name]) { if(this.currentAnim.isPlaying == false) { @@ -7881,6 +7875,8 @@ var Phaser; } var width = img.width; var height = img.height; + frameWidth *= game.stage.globalScale; + frameHeight *= game.stage.globalScale; var row = Math.round(width / frameWidth); var column = Math.round(height / frameHeight); var total = row * column; @@ -12658,14 +12654,21 @@ var Phaser; this._dw = sprite.crop.width * sprite.transform.scale.x; this._dh = sprite.crop.height * sprite.transform.scale.y; } - this._sx = Math.floor(this._sx); - this._sy = Math.floor(this._sy); - this._sw = Math.floor(this._sw); - this._sh = Math.floor(this._sh); - this._dx = Math.floor(this._dx); - this._dy = Math.floor(this._dy); - this._dw = Math.floor(this._dw); - this._dh = Math.floor(this._dh); + if(this.game.stage.globalScale != 1) { + this._sx = Math.floor(this._sx * this.game.stage.globalScale); + this._sy = Math.floor(this._sy * this.game.stage.globalScale); + this._dx = Math.floor(this._dx * this.game.stage.globalScale); + this._dy = Math.floor(this._dy * this.game.stage.globalScale); + } else { + this._sx = Math.floor(this._sx); + this._sy = Math.floor(this._sy); + this._sw = Math.floor(this._sw); + this._sh = Math.floor(this._sh); + this._dx = Math.floor(this._dx); + this._dy = Math.floor(this._dy); + this._dw = Math.floor(this._dw); + this._dh = Math.floor(this._dh); + } if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) { return false; } @@ -13984,6 +13987,7 @@ var Phaser; var Stage = (function () { function Stage(game, parent, width, height) { var _this = this; + this.globalScale = 1; this._backgroundColor = 'rgb(0,0,0)'; this.clear = true; this.disablePauseScreen = false; @@ -14259,6 +14263,12 @@ var Phaser; this.onDestroyCallback = null; this.isBooted = false; this.isRunning = false; + if(window['PhaserGlobal'].singleInstance) { + if(Phaser.GAMES.length > 0) { + console.log('Phaser detected an instance of this game already running, aborting'); + return; + } + } this.id = Phaser.GAMES.push(this) - 1; this.callbackContext = callbackContext; this.onPreloadCallback = preloadCallback; diff --git a/build/phaser-debug.js b/build/phaser-debug.js index 5f2f2233..a6300a14 100644 --- a/build/phaser-debug.js +++ b/build/phaser-debug.js @@ -5963,7 +5963,7 @@ var Phaser; this.maxHeight = null; this.width = 0; this.height = 0; - this.maxIterations = 10; + this.maxIterations = 5; this.game = game; this.enterLandscape = new Phaser.Signal(); this.enterPortrait = new Phaser.Signal(); @@ -6025,9 +6025,6 @@ var Phaser; } }; StageScaleMode.prototype.update = function () { - if(this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE && (window.innerWidth !== this.width || window.innerHeight !== this.height)) { - this.refresh(); - } if(this.forceLandscape || this.forcePortrait) { this.checkOrientationState(); }