From ecf61fc80ca59514168d5304d471d29f61a1d6b6 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Sun, 25 Aug 2013 09:59:23 +0100 Subject: [PATCH] Updated Game.switchState to accept state objects and fixed the OrientationScreen. --- Phaser/Game.ts | 4 ++ Phaser/Phaser.csproj | 2 +- Phaser/Stage.ts | 2 +- Phaser/system/screens/OrientationScreen.ts | 40 ++++++----------- Phaser/time/TimeManager.ts | 2 +- README.md | 14 ++++-- Tests/phaser-debug.js | 52 ++++++++-------------- build/phaser-debug.js | 26 +++++------ 8 files changed, 61 insertions(+), 81 deletions(-) diff --git a/Phaser/Game.ts b/Phaser/Game.ts index 18fef7a3..3b2ca165 100644 --- a/Phaser/Game.ts +++ b/Phaser/Game.ts @@ -550,6 +550,10 @@ module Phaser { { this.state = new state(this); } + else + { + this.state = state; + } // Ok, have we got the right functions? if (this.state['create'] || this.state['update']) diff --git a/Phaser/Phaser.csproj b/Phaser/Phaser.csproj index c29b3cfc..82d97d95 100644 --- a/Phaser/Phaser.csproj +++ b/Phaser/Phaser.csproj @@ -2,7 +2,7 @@ Debug - {A90BE60F-CAEA-4747-904A-CDB097BA2459} + {BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA} {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} Library bin diff --git a/Phaser/Stage.ts b/Phaser/Stage.ts index cec7d46b..6c55ceec 100644 --- a/Phaser/Stage.ts +++ b/Phaser/Stage.ts @@ -249,7 +249,7 @@ module Phaser { this.scale.forceLandscape = forceLandscape; this.scale.forcePortrait = forcePortrait; - this.orientationScreen.enable(forceLandscape, forcePortrait, imageKey); + this.orientationScreen.enable(imageKey); if (forceLandscape || forcePortrait) { diff --git a/Phaser/system/screens/OrientationScreen.ts b/Phaser/system/screens/OrientationScreen.ts index ae7eb448..1a3ea3a0 100644 --- a/Phaser/system/screens/OrientationScreen.ts +++ b/Phaser/system/screens/OrientationScreen.ts @@ -12,48 +12,40 @@ module Phaser { /** * OrientationScreen constructor - * Create a new OrientationScreen with specific width and height. - * - * @param width {number} Screen canvas width. - * @param height {number} Screen canvas height. + * Create a new OrientationScreen. */ constructor(game: Phaser.Game) { this.game = game; } + private _enabled: bool = false; + /** * Local reference to game. */ public game: Phaser.Game; - private _showOnLandscape: bool = false; - private _showOnPortrait: bool = false; - /** - * Landscape Image. If you only want your game to work in Portrait mode, and display an image when in Landscape, - * then set this to be the key of an image previously loaded into the Game.Cache. + * The image to be displayed when the device is rotated to an unsupported orientation. + * Set this to be the key of an image previously loaded into the Game.Cache. * @type {Cache Reference} */ - public landscapeImage; + public image; /** - * Portrait Image. If you only want your game to work in Landscape mode, and display an image when in Portrait, - * then set this to be the key of an image previously loaded into the Game.Cache. + * Enable the orientation screen. An image that is displayed whenever the device enters an unsupported orientation. + * Set this to be the key of an image previously loaded into the Game.Cache. * @type {Cache Reference} */ - public portraitImage; + public enable(imageKey: string) { - public enable(onLandscape: bool, onPortrait: bool, imageKey: string) { - - this._showOnLandscape = onLandscape; - this._showOnPortrait = onPortrait; - this.landscapeImage = this.game.cache.getImage(imageKey); - this.portraitImage = this.game.cache.getImage(imageKey); + this._enabled = true; + this.image = this.game.cache.getImage(imageKey); } /** - * Update + * Update (can be overridden) */ public update() { } @@ -63,13 +55,9 @@ module Phaser { */ public render() { - if (this._showOnLandscape) + if (this._enabled) { - 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); + 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); } } diff --git a/Phaser/time/TimeManager.ts b/Phaser/time/TimeManager.ts index dc446f45..5902aec5 100644 --- a/Phaser/time/TimeManager.ts +++ b/Phaser/time/TimeManager.ts @@ -52,7 +52,7 @@ module Phaser { * @public * @type {Number} */ - public elapsed: number = 0; + //public elapsed: number = 0; /** * The elapsed time calculated for the physics motion updates. diff --git a/README.md b/README.md index 6ad01bb6..131b2f41 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Phaser ====== -Version: 1.0.0 - Released: August 12th 2013 +Version: 1.0.0 - Released: August 2013 By Richard Davey, [Photon Storm](http://www.photonstorm.com) @@ -45,7 +45,6 @@ ToDo before release * Move embedded Phaser logo outside or swap for canvas calls * Put Device.getAll elsewhere (plugin? utils?) * Investigate bug re: tilemap collision and animation frames -* Allow camera to directly render to the stage rather than hidden ctx (maybe does this by default? or have under Mobile Optimisations list) * Sprite collision events * Check bounds/edge points when sprite is only 1x1 sized :) * QuadTree.physics.checkHullIntersection @@ -53,13 +52,20 @@ ToDo before release * When game paused should mute-all then resume-all sounds? * Bitmap Font support * Pixel-perfect click check -* Check Flash atlas export is supported +* Check Flash atlas export is working * DynamicTexture.setPixel needs to be swapped for a proper pixel put, not the filledRect it currently is. * Check multi-game support (2+ games on one page) -* Docs! +* Finish the Docs! * Getting Started guide! +* Sprite Sheet / Atlas support for Dynamic Textures +Mobile Optimisation Suggestions +------------------------------- + +* Camera.directToStage +* Stage.clear + Latest Update ------------- diff --git a/Tests/phaser-debug.js b/Tests/phaser-debug.js index 2b141b0b..b778b42c 100644 --- a/Tests/phaser-debug.js +++ b/Tests/phaser-debug.js @@ -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; diff --git a/build/phaser-debug.js b/build/phaser-debug.js index a6300a14..b778b42c 100644 --- a/build/phaser-debug.js +++ b/build/phaser-debug.js @@ -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; @@ -12605,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); @@ -14067,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; @@ -14253,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; @@ -14432,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;