mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
Updated Game.switchState to accept state objects and fixed the OrientationScreen.
This commit is contained in:
@@ -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'])
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<ProjectGuid>{A90BE60F-CAEA-4747-904A-CDB097BA2459}</ProjectGuid>
|
||||
<ProjectGuid>{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}</ProjectGuid>
|
||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<OutputPath>bin</OutputPath>
|
||||
|
||||
+1
-1
@@ -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)
|
||||
{
|
||||
|
||||
@@ -12,48 +12,40 @@ module Phaser {
|
||||
|
||||
/**
|
||||
* OrientationScreen constructor
|
||||
* Create a new <code>OrientationScreen</code> with specific width and height.
|
||||
*
|
||||
* @param width {number} Screen canvas width.
|
||||
* @param height {number} Screen canvas height.
|
||||
* Create a new <code>OrientationScreen</code>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
-------------
|
||||
|
||||
|
||||
+19
-33
@@ -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;
|
||||
|
||||
+11
-15
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user