Updated Game.switchState to accept state objects and fixed the OrientationScreen.

This commit is contained in:
Richard Davey
2013-08-25 09:59:23 +01:00
parent c2745bec35
commit ecf61fc80c
8 changed files with 61 additions and 81 deletions
+19 -33
View File
@@ -4064,7 +4064,6 @@ var Phaser;
(function (Phaser) {
var TimeManager = (function () {
function TimeManager(game) {
this.elapsed = 0;
this.physicsElapsed = 0;
this.time = 0;
this.pausedTime = 0;
@@ -6264,23 +6263,18 @@ var Phaser;
(function (Phaser) {
var OrientationScreen = (function () {
function OrientationScreen(game) {
this._showOnLandscape = false;
this._showOnPortrait = false;
this._enabled = false;
this.game = game;
}
OrientationScreen.prototype.enable = function (onLandscape, onPortrait, imageKey) {
this._showOnLandscape = onLandscape;
this._showOnPortrait = onPortrait;
this.landscapeImage = this.game.cache.getImage(imageKey);
this.portraitImage = this.game.cache.getImage(imageKey);
OrientationScreen.prototype.enable = function (imageKey) {
this._enabled = true;
this.image = this.game.cache.getImage(imageKey);
};
OrientationScreen.prototype.update = function () {
};
OrientationScreen.prototype.render = function () {
if(this._showOnLandscape) {
this.game.stage.context.drawImage(this.landscapeImage, 0, 0, this.landscapeImage.width, this.landscapeImage.height, 0, 0, this.game.stage.width, this.game.stage.height);
} else if(this._showOnPortrait) {
this.game.stage.context.drawImage(this.portraitImage, 0, 0, this.portraitImage.width, this.portraitImage.height, 0, 0, this.game.stage.width, this.game.stage.height);
if(this._enabled) {
this.game.stage.context.drawImage(this.image, 0, 0, this.image.width, this.image.height, 0, 0, this.game.stage.width, this.game.stage.height);
}
};
return OrientationScreen;
@@ -7875,8 +7869,6 @@ 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;
@@ -12607,7 +12599,7 @@ var Phaser;
if(sprite.transform.scrollFactor.equals(0)) {
return true;
}
return true;
return Phaser.RectangleUtils.intersects(sprite.cameraView, camera.screenView);
};
SpriteRenderer.prototype.render = function (camera, sprite) {
Phaser.SpriteUtils.updateCameraView(camera, sprite);
@@ -12654,21 +12646,14 @@ var Phaser;
this._dw = sprite.crop.width * sprite.transform.scale.x;
this._dh = sprite.crop.height * sprite.transform.scale.y;
}
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);
}
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;
}
@@ -13987,7 +13972,6 @@ 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;
@@ -14077,7 +14061,7 @@ var Phaser;
if (typeof imageKey === "undefined") { imageKey = ''; }
this.scale.forceLandscape = forceLandscape;
this.scale.forcePortrait = forcePortrait;
this.orientationScreen.enable(forceLandscape, forcePortrait, imageKey);
this.orientationScreen.enable(imageKey);
if(forceLandscape || forcePortrait) {
if((this.scale.isLandscape && forcePortrait) || (this.scale.isPortrait && forceLandscape)) {
this.game.paused = true;
@@ -14263,7 +14247,7 @@ var Phaser;
this.onDestroyCallback = null;
this.isBooted = false;
this.isRunning = false;
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');
return;
@@ -14442,6 +14426,8 @@ var Phaser;
this.input.reset(true);
if(typeof state === 'function') {
this.state = new state(this);
} else {
this.state = state;
}
if(this.state['create'] || this.state['update']) {
this.callbackContext = this.state;