Fixed instance check issue in Game and tidied up the stageScaleMode inner loop.

This commit is contained in:
Richard Davey 2013-08-16 02:18:12 +01:00
parent f76ba6840f
commit c884bab7ec
6 changed files with 55 additions and 26 deletions

View file

@ -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;
}
}

View file

@ -38,6 +38,8 @@ module Phaser {
}
public game: Phaser.Game;
/**
* X position within the image to cut from.
* @type {number}

View file

@ -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;

View file

@ -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();
}
*/
}

View file

@ -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;

View file

@ -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();
}