Skip to content

Commit ecf61fc

Browse files
committed
Updated Game.switchState to accept state objects and fixed the OrientationScreen.
1 parent c2745be commit ecf61fc

8 files changed

Lines changed: 61 additions & 81 deletions

File tree

Phaser/Game.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ module Phaser {
550550
{
551551
this.state = new state(this);
552552
}
553+
else
554+
{
555+
this.state = state;
556+
}
553557

554558
// Ok, have we got the right functions?
555559
if (this.state['create'] || this.state['update'])

Phaser/Phaser.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<ProjectGuid>{A90BE60F-CAEA-4747-904A-CDB097BA2459}</ProjectGuid>
5+
<ProjectGuid>{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}</ProjectGuid>
66
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
77
<OutputType>Library</OutputType>
88
<OutputPath>bin</OutputPath>

Phaser/Stage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ module Phaser {
249249

250250
this.scale.forceLandscape = forceLandscape;
251251
this.scale.forcePortrait = forcePortrait;
252-
this.orientationScreen.enable(forceLandscape, forcePortrait, imageKey);
252+
this.orientationScreen.enable(imageKey);
253253

254254
if (forceLandscape || forcePortrait)
255255
{

Phaser/system/screens/OrientationScreen.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,40 @@ module Phaser {
1212

1313
/**
1414
* OrientationScreen constructor
15-
* Create a new <code>OrientationScreen</code> with specific width and height.
16-
*
17-
* @param width {number} Screen canvas width.
18-
* @param height {number} Screen canvas height.
15+
* Create a new <code>OrientationScreen</code>.
1916
*/
2017
constructor(game: Phaser.Game) {
2118
this.game = game;
2219
}
2320

21+
private _enabled: bool = false;
22+
2423
/**
2524
* Local reference to game.
2625
*/
2726
public game: Phaser.Game;
2827

29-
private _showOnLandscape: bool = false;
30-
private _showOnPortrait: bool = false;
31-
3228
/**
33-
* Landscape Image. If you only want your game to work in Portrait mode, and display an image when in Landscape,
34-
* then set this to be the key of an image previously loaded into the Game.Cache.
29+
* The image to be displayed when the device is rotated to an unsupported orientation.
30+
* Set this to be the key of an image previously loaded into the Game.Cache.
3531
* @type {Cache Reference}
3632
*/
37-
public landscapeImage;
33+
public image;
3834

3935
/**
40-
* Portrait Image. If you only want your game to work in Landscape mode, and display an image when in Portrait,
41-
* then set this to be the key of an image previously loaded into the Game.Cache.
36+
* Enable the orientation screen. An image that is displayed whenever the device enters an unsupported orientation.
37+
* Set this to be the key of an image previously loaded into the Game.Cache.
4238
* @type {Cache Reference}
4339
*/
44-
public portraitImage;
45-
46-
public enable(onLandscape: bool, onPortrait: bool, imageKey: string) {
40+
public enable(imageKey: string) {
4741

48-
this._showOnLandscape = onLandscape;
49-
this._showOnPortrait = onPortrait;
50-
this.landscapeImage = this.game.cache.getImage(imageKey);
51-
this.portraitImage = this.game.cache.getImage(imageKey);
42+
this._enabled = true;
43+
this.image = this.game.cache.getImage(imageKey);
5244

5345
}
5446

5547
/**
56-
* Update
48+
* Update (can be overridden)
5749
*/
5850
public update() {
5951
}
@@ -63,13 +55,9 @@ module Phaser {
6355
*/
6456
public render() {
6557

66-
if (this._showOnLandscape)
67-
{
68-
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);
69-
}
70-
else if (this._showOnPortrait)
58+
if (this._enabled)
7159
{
72-
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);
60+
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);
7361
}
7462

7563
}

Phaser/time/TimeManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module Phaser {
5252
* @public
5353
* @type {Number}
5454
*/
55-
public elapsed: number = 0;
55+
//public elapsed: number = 0;
5656

5757
/**
5858
* The elapsed time calculated for the physics motion updates.

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Phaser
22
======
33

4-
Version: 1.0.0 - Released: August 12th 2013
4+
Version: 1.0.0 - Released: August 2013
55

66
By Richard Davey, [Photon Storm](http://www.photonstorm.com)
77

@@ -45,21 +45,27 @@ ToDo before release
4545
* Move embedded Phaser logo outside or swap for canvas calls
4646
* Put Device.getAll elsewhere (plugin? utils?)
4747
* Investigate bug re: tilemap collision and animation frames
48-
* Allow camera to directly render to the stage rather than hidden ctx (maybe does this by default? or have under Mobile Optimisations list)
4948
* Sprite collision events
5049
* Check bounds/edge points when sprite is only 1x1 sized :)
5150
* QuadTree.physics.checkHullIntersection
5251
* Sprite.transform.bottomRight/Left doesn't seem to take origin into account
5352
* When game paused should mute-all then resume-all sounds?
5453
* Bitmap Font support
5554
* Pixel-perfect click check
56-
* Check Flash atlas export is supported
55+
* Check Flash atlas export is working
5756
* DynamicTexture.setPixel needs to be swapped for a proper pixel put, not the filledRect it currently is.
5857
* Check multi-game support (2+ games on one page)
59-
* Docs!
58+
* Finish the Docs!
6059
* Getting Started guide!
60+
* Sprite Sheet / Atlas support for Dynamic Textures
6161

6262

63+
Mobile Optimisation Suggestions
64+
-------------------------------
65+
66+
* Camera.directToStage
67+
* Stage.clear
68+
6369
Latest Update
6470
-------------
6571

Tests/phaser-debug.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,7 +4064,6 @@ var Phaser;
40644064
(function (Phaser) {
40654065
var TimeManager = (function () {
40664066
function TimeManager(game) {
4067-
this.elapsed = 0;
40684067
this.physicsElapsed = 0;
40694068
this.time = 0;
40704069
this.pausedTime = 0;
@@ -6264,23 +6263,18 @@ var Phaser;
62646263
(function (Phaser) {
62656264
var OrientationScreen = (function () {
62666265
function OrientationScreen(game) {
6267-
this._showOnLandscape = false;
6268-
this._showOnPortrait = false;
6266+
this._enabled = false;
62696267
this.game = game;
62706268
}
6271-
OrientationScreen.prototype.enable = function (onLandscape, onPortrait, imageKey) {
6272-
this._showOnLandscape = onLandscape;
6273-
this._showOnPortrait = onPortrait;
6274-
this.landscapeImage = this.game.cache.getImage(imageKey);
6275-
this.portraitImage = this.game.cache.getImage(imageKey);
6269+
OrientationScreen.prototype.enable = function (imageKey) {
6270+
this._enabled = true;
6271+
this.image = this.game.cache.getImage(imageKey);
62766272
};
62776273
OrientationScreen.prototype.update = function () {
62786274
};
62796275
OrientationScreen.prototype.render = function () {
6280-
if(this._showOnLandscape) {
6281-
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);
6282-
} else if(this._showOnPortrait) {
6283-
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);
6276+
if(this._enabled) {
6277+
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);
62846278
}
62856279
};
62866280
return OrientationScreen;
@@ -7875,8 +7869,6 @@ var Phaser;
78757869
}
78767870
var width = img.width;
78777871
var height = img.height;
7878-
frameWidth *= game.stage.globalScale;
7879-
frameHeight *= game.stage.globalScale;
78807872
var row = Math.round(width / frameWidth);
78817873
var column = Math.round(height / frameHeight);
78827874
var total = row * column;
@@ -12607,7 +12599,7 @@ var Phaser;
1260712599
if(sprite.transform.scrollFactor.equals(0)) {
1260812600
return true;
1260912601
}
12610-
return true;
12602+
return Phaser.RectangleUtils.intersects(sprite.cameraView, camera.screenView);
1261112603
};
1261212604
SpriteRenderer.prototype.render = function (camera, sprite) {
1261312605
Phaser.SpriteUtils.updateCameraView(camera, sprite);
@@ -12654,21 +12646,14 @@ var Phaser;
1265412646
this._dw = sprite.crop.width * sprite.transform.scale.x;
1265512647
this._dh = sprite.crop.height * sprite.transform.scale.y;
1265612648
}
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-
}
12649+
this._sx = Math.floor(this._sx);
12650+
this._sy = Math.floor(this._sy);
12651+
this._sw = Math.floor(this._sw);
12652+
this._sh = Math.floor(this._sh);
12653+
this._dx = Math.floor(this._dx);
12654+
this._dy = Math.floor(this._dy);
12655+
this._dw = Math.floor(this._dw);
12656+
this._dh = Math.floor(this._dh);
1267212657
if(this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0) {
1267312658
return false;
1267412659
}
@@ -13987,7 +13972,6 @@ var Phaser;
1398713972
var Stage = (function () {
1398813973
function Stage(game, parent, width, height) {
1398913974
var _this = this;
13990-
this.globalScale = 1;
1399113975
this._backgroundColor = 'rgb(0,0,0)';
1399213976
this.clear = true;
1399313977
this.disablePauseScreen = false;
@@ -14077,7 +14061,7 @@ var Phaser;
1407714061
if (typeof imageKey === "undefined") { imageKey = ''; }
1407814062
this.scale.forceLandscape = forceLandscape;
1407914063
this.scale.forcePortrait = forcePortrait;
14080-
this.orientationScreen.enable(forceLandscape, forcePortrait, imageKey);
14064+
this.orientationScreen.enable(imageKey);
1408114065
if(forceLandscape || forcePortrait) {
1408214066
if((this.scale.isLandscape && forcePortrait) || (this.scale.isPortrait && forceLandscape)) {
1408314067
this.game.paused = true;
@@ -14263,7 +14247,7 @@ var Phaser;
1426314247
this.onDestroyCallback = null;
1426414248
this.isBooted = false;
1426514249
this.isRunning = false;
14266-
if(window['PhaserGlobal'].singleInstance) {
14250+
if(window['PhaserGlobal'] && window['PhaserGlobal'].singleInstance) {
1426714251
if(Phaser.GAMES.length > 0) {
1426814252
console.log('Phaser detected an instance of this game already running, aborting');
1426914253
return;
@@ -14442,6 +14426,8 @@ var Phaser;
1444214426
this.input.reset(true);
1444314427
if(typeof state === 'function') {
1444414428
this.state = new state(this);
14429+
} else {
14430+
this.state = state;
1444514431
}
1444614432
if(this.state['create'] || this.state['update']) {
1444714433
this.callbackContext = this.state;

build/phaser-debug.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,7 +4064,6 @@ var Phaser;
40644064
(function (Phaser) {
40654065
var TimeManager = (function () {
40664066
function TimeManager(game) {
4067-
this.elapsed = 0;
40684067
this.physicsElapsed = 0;
40694068
this.time = 0;
40704069
this.pausedTime = 0;
@@ -6264,23 +6263,18 @@ var Phaser;
62646263
(function (Phaser) {
62656264
var OrientationScreen = (function () {
62666265
function OrientationScreen(game) {
6267-
this._showOnLandscape = false;
6268-
this._showOnPortrait = false;
6266+
this._enabled = false;
62696267
this.game = game;
62706268
}
6271-
OrientationScreen.prototype.enable = function (onLandscape, onPortrait, imageKey) {
6272-
this._showOnLandscape = onLandscape;
6273-
this._showOnPortrait = onPortrait;
6274-
this.landscapeImage = this.game.cache.getImage(imageKey);
6275-
this.portraitImage = this.game.cache.getImage(imageKey);
6269+
OrientationScreen.prototype.enable = function (imageKey) {
6270+
this._enabled = true;
6271+
this.image = this.game.cache.getImage(imageKey);
62766272
};
62776273
OrientationScreen.prototype.update = function () {
62786274
};
62796275
OrientationScreen.prototype.render = function () {
6280-
if(this._showOnLandscape) {
6281-
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);
6282-
} else if(this._showOnPortrait) {
6283-
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);
6276+
if(this._enabled) {
6277+
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);
62846278
}
62856279
};
62866280
return OrientationScreen;
@@ -12605,7 +12599,7 @@ var Phaser;
1260512599
if(sprite.transform.scrollFactor.equals(0)) {
1260612600
return true;
1260712601
}
12608-
return true;
12602+
return Phaser.RectangleUtils.intersects(sprite.cameraView, camera.screenView);
1260912603
};
1261012604
SpriteRenderer.prototype.render = function (camera, sprite) {
1261112605
Phaser.SpriteUtils.updateCameraView(camera, sprite);
@@ -14067,7 +14061,7 @@ var Phaser;
1406714061
if (typeof imageKey === "undefined") { imageKey = ''; }
1406814062
this.scale.forceLandscape = forceLandscape;
1406914063
this.scale.forcePortrait = forcePortrait;
14070-
this.orientationScreen.enable(forceLandscape, forcePortrait, imageKey);
14064+
this.orientationScreen.enable(imageKey);
1407114065
if(forceLandscape || forcePortrait) {
1407214066
if((this.scale.isLandscape && forcePortrait) || (this.scale.isPortrait && forceLandscape)) {
1407314067
this.game.paused = true;
@@ -14253,7 +14247,7 @@ var Phaser;
1425314247
this.onDestroyCallback = null;
1425414248
this.isBooted = false;
1425514249
this.isRunning = false;
14256-
if(window['PhaserGlobal'].singleInstance) {
14250+
if(window['PhaserGlobal'] && window['PhaserGlobal'].singleInstance) {
1425714251
if(Phaser.GAMES.length > 0) {
1425814252
console.log('Phaser detected an instance of this game already running, aborting');
1425914253
return;
@@ -14432,6 +14426,8 @@ var Phaser;
1443214426
this.input.reset(true);
1443314427
if(typeof state === 'function') {
1443414428
this.state = new state(this);
14429+
} else {
14430+
this.state = state;
1443514431
}
1443614432
if(this.state['create'] || this.state['update']) {
1443714433
this.callbackContext = this.state;

0 commit comments

Comments
 (0)