Phaser.StageScaleMode has been renamed to ScaleManager and moved from the system folder to the core folder. It's still available under game.scale.

If your game references the old Phaser.StageScaleMode consts like SHOW_ALL you need to update them to Phaser.ScaleManager, i.e. Phaser.ScaleManager.SHOW_ALL.
All of the Project Templates have been updated to reflect the above change.
This commit is contained in:
photonstorm
2014-02-25 14:46:48 +00:00
parent fdde4cb7e6
commit 13c99f3491
22 changed files with 321 additions and 112 deletions
+1 -1
View File
@@ -70,6 +70,7 @@ module.exports = function (grunt) {
'src/core/Stage.js',
'src/core/Group.js',
'src/core/World.js',
'src/core/ScaleManager.js',
'src/core/Game.js',
'src/input/Input.js',
@@ -100,7 +101,6 @@ module.exports = function (grunt) {
'src/gameobjects/BitmapFont.js',
'src/system/Canvas.js',
'src/system/StageScaleMode.js',
'src/system/Device.js',
'src/system/RequestAnimationFrame.js',
+2
View File
@@ -78,6 +78,8 @@ Significant API changes:
* Keyboard.removeKey has been removed. The way the new keyboard manager works means it's no longer required.
* When a game un-pauses (from a visibility loss) it resets all Input components.
* Time.advancedTiming is a new boolean property. If true Time.fps, fpsMin, fpsMax, frames, msMin and msMax will be calculated, otherwise they remain at their defaults.
* Phaser.StageScaleMode has been renamed to ScaleManager and moved from the system folder to the core folder. It's still available under game.scale.
* If your game references the old Phaser.StageScaleMode consts like SHOW_ALL you need to update them to Phaser.ScaleManager, i.e. Phaser.ScaleManager.SHOW_ALL.
New features:
+1 -1
View File
@@ -117,6 +117,7 @@
<script src="$path/src/core/Group.js"></script>
<script src="$path/src/core/World.js"></script>
<script src="$path/src/core/Game.js"></script>
<script src="$path/src/core/ScaleManager.js"></script>
<script src="$path/src/input/Input.js"></script>
<script src="$path/src/input/Key.js"></script>
@@ -146,7 +147,6 @@
<script src="$path/src/gameobjects/BitmapFont.js"></script>
<script src="$path/src/system/Canvas.js"></script>
<script src="$path/src/system/StageScaleMode.js"></script>
<script src="$path/src/system/Device.js"></script>
<script src="$path/src/system/RequestAnimationFrame.js"></script>
+1 -1
View File
@@ -71,6 +71,7 @@
<script src="../src/core/Stage.js"></script>
<script src="../src/core/Group.js"></script>
<script src="../src/core/World.js"></script>
<script src="../src/core/ScaleManager.js"></script>
<script src="../src/core/Game.js"></script>
<script src="../src/input/Input.js"></script>
@@ -101,7 +102,6 @@
<script src="../src/gameobjects/BitmapFont.js"></script>
<script src="../src/system/Canvas.js"></script>
<script src="../src/system/StageScaleMode.js"></script>
<script src="../src/system/Device.js"></script>
<script src="../src/system/RequestAnimationFrame.js"></script>
+1 -1
View File
@@ -71,6 +71,7 @@
<script src="../src/core/Stage.js"></script>
<script src="../src/core/Group.js"></script>
<script src="../src/core/World.js"></script>
<script src="../src/core/ScaleManager.js"></script>
<script src="../src/core/Game.js"></script>
<script src="../src/input/Input.js"></script>
@@ -101,7 +102,6 @@
<script src="../src/gameobjects/BitmapFont.js"></script>
<script src="../src/system/Canvas.js"></script>
<script src="../src/system/StageScaleMode.js"></script>
<script src="../src/system/Device.js"></script>
<script src="../src/system/RequestAnimationFrame.js"></script>
+4
View File
@@ -20,6 +20,10 @@ function create() {
sprite = game.add.tileSprite(0, 0, 800, 600, 'starfield');
sprite.autoScroll(0, 200);
game.add.image(200, 200, 'mummy');
game.world.scale.set(2);
}
function update() {
+36
View File
@@ -0,0 +1,36 @@
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
}
var mummy;
var anim;
function create() {
game.stage.backgroundColor = 0xff8855;
mummy = game.add.sprite(300, 200, 'mummy', 5);
mummy.animations.updateIfVisible = false;
anim = mummy.animations.add('walk');
anim.play(2, false);
// anim.play(2, true);
}
function update() {
}
function render() {
game.debug.renderText(anim.frame + ' / 17', 32, 32);
}
+77
View File
@@ -0,0 +1,77 @@
var BasicGame = {};
BasicGame.Boot = function (game) {
};
BasicGame.Boot.prototype = {
preload: function () {
this.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
},
create: function () {
this.state.start('MainMenu');
}
};
BasicGame.MainMenu = function (game) {
this.mummy;
this.anim;
};
BasicGame.MainMenu.prototype = {
create: function () {
this.stage.backgroundColor = 0x2d2d2d;
this.mummy = this.add.sprite(200, 400, 'mummy');
this.anim = this.mummy.animations.add('walk');
this.anim.play(10, false);
this.mummy.events.onAnimationComplete.add(this.changeIt, this);
},
changeIt: function () {
this.state.start('GameOver');
}
};
BasicGame.GameOver = function (game) {
this.dude;
};
BasicGame.GameOver.prototype = {
create: function () {
this.stage.backgroundColor = 0xff7744;
this.dude = this.add.sprite(300, 300, 'mummy');
}
};
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example');
game.state.add('Boot', BasicGame.Boot);
game.state.add('MainMenu', BasicGame.MainMenu);
game.state.add('GameOver', BasicGame.GameOver);
game.state.start('Boot');
+1 -1
View File
@@ -89,4 +89,4 @@ game.state.add('Boot', BasicGame.Boot);
game.state.add('Preloader', BasicGame.Preloader);
game.state.add('MainMenu', BasicGame.MainMenu);
game.state.start('Boot', true, false, 'hello', 'world');
game.state.start('Boot');
+13 -13
View File
@@ -1,4 +1,4 @@
BasicGame = {};
var BasicGame = {};
BasicGame.Boot = function (game) {
@@ -17,33 +17,33 @@ BasicGame.Boot.prototype = {
create: function () {
// Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1
this.game.input.maxPointers = 1;
this.input.maxPointers = 1;
// Phaser will automatically pause if the browser tab the game is in loses focus. You can disable that here:
this.game.stage.disableVisibilityChange = true;
this.stage.disableVisibilityChange = true;
if (this.game.device.desktop)
{
// If you have any desktop specific settings, they can go in here
this.game.stage.scale.pageAlignHorizontally = true;
this.scale.pageAlignHorizontally = true;
}
else
{
// Same goes for mobile settings.
// In this case we're saying "scale the game, no lower than 480x260 and no higher than 1024x768"
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
this.game.stage.scale.minWidth = 480;
this.game.stage.scale.minHeight = 260;
this.game.stage.scale.maxWidth = 1024;
this.game.stage.scale.maxHeight = 768;
this.game.stage.scale.forceLandscape = true;
this.game.stage.scale.pageAlignHorizontally = true;
this.game.stage.scale.setScreenSize(true);
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.minWidth = 480;
this.scale.minHeight = 260;
this.scale.maxWidth = 1024;
this.scale.maxHeight = 768;
this.scale.forceLandscape = true;
this.scale.pageAlignHorizontally = true;
this.scale.setScreenSize(true);
}
// By this point the preloader assets have loaded to the cache, we've set the game settings
// So now let's start the real preloader going
this.game.state.start('Preloader');
this.state.start('Preloader');
}
+3 -2
View File
@@ -13,7 +13,8 @@ BasicGame.Game = function (game) {
this.sound; // the sound manager - add a sound, play one, set-up markers, etc
this.stage; // the game stage
this.time; // the clock
this.tweens; // the tween manager
this.tweens; // the tween manager
this.state; // the state manager
this.world; // the game world
this.particles; // the particle manager
this.physics; // the physics manager
@@ -44,7 +45,7 @@ BasicGame.Game.prototype = {
// Stop music, delete sprites, purge caches, free resources, all that good stuff.
// Then let's go back to the main menu.
this.game.state.start('MainMenu');
this.state.start('MainMenu');
}
@@ -35,7 +35,7 @@ BasicGame.MainMenu.prototype = {
this.music.stop();
// And start the actual game
this.game.state.start('Game');
this.state.start('Game');
}
@@ -53,7 +53,7 @@ BasicGame.Preloader.prototype = {
if (this.cache.isSoundDecoded('titleMusic') && this.ready == false)
{
this.ready = true;
this.game.state.start('MainMenu');
this.state.start('MainMenu');
}
}
@@ -26,37 +26,37 @@ BasicGame.Boot.prototype = {
create: function () {
this.game.input.maxPointers = 1;
this.game.stage.disableVisibilityChange = true;
this.input.maxPointers = 1;
this.stage.disableVisibilityChange = true;
if (this.game.device.desktop)
{
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
this.game.stage.scale.minWidth = 480;
this.game.stage.scale.minHeight = 260;
this.game.stage.scale.maxWidth = 1024;
this.game.stage.scale.maxHeight = 768;
this.game.stage.scale.pageAlignHorizontally = true;
this.game.stage.scale.pageAlignVertically = true;
this.game.stage.scale.setScreenSize(true);
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.minWidth = 480;
this.scale.minHeight = 260;
this.scale.maxWidth = 1024;
this.scale.maxHeight = 768;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
this.scale.setScreenSize(true);
}
else
{
this.game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL;
this.game.stage.scale.minWidth = 480;
this.game.stage.scale.minHeight = 260;
this.game.stage.scale.maxWidth = 1024;
this.game.stage.scale.maxHeight = 768;
this.game.stage.scale.pageAlignHorizontally = true;
this.game.stage.scale.pageAlignVertically = true;
this.game.stage.scale.forceOrientation(true, false);
this.game.stage.scale.hasResized.add(this.gameResized, this);
this.game.stage.scale.enterIncorrectOrientation.add(this.enterIncorrectOrientation, this);
this.game.stage.scale.leaveIncorrectOrientation.add(this.leaveIncorrectOrientation, this);
this.game.stage.scale.setScreenSize(true);
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.minWidth = 480;
this.scale.minHeight = 260;
this.scale.maxWidth = 1024;
this.scale.maxHeight = 768;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
this.scale.forceOrientation(true, false);
this.scale.hasResized.add(this.gameResized, this);
this.scale.enterIncorrectOrientation.add(this.enterIncorrectOrientation, this);
this.scale.leaveIncorrectOrientation.add(this.leaveIncorrectOrientation, this);
this.scale.setScreenSize(true);
}
this.game.state.start('Preloader');
this.state.start('Preloader');
},
@@ -44,7 +44,7 @@ BasicGame.Game.prototype = {
// Stop music, delete sprites, purge caches, free resources, all that good stuff.
// Then let's go back to the main menu.
this.game.state.start('MainMenu');
this.state.start('MainMenu');
}
@@ -35,7 +35,7 @@ BasicGame.MainMenu.prototype = {
this.music.stop();
// And start the actual game
this.game.state.start('Game');
this.state.start('Game');
}
@@ -53,7 +53,7 @@ BasicGame.Preloader.prototype = {
if (this.cache.isSoundDecoded('titleMusic') && this.ready == false)
{
this.ready = true;
this.game.state.start('MainMenu');
this.state.start('MainMenu');
}
}
+3 -2
View File
@@ -142,7 +142,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
this.net = null;
/**
* @property {Phaser.StageScaleMode} scale - The game scale manager.
* @property {Phaser.ScaleManager} scale - The game scale manager.
*/
this.scale = null;
@@ -446,7 +446,7 @@ Phaser.Game.prototype = {
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
this.stage = new Phaser.Stage(this, this.width, this.height);
this.scale = new Phaser.StageScaleMode(this, this.width, this.height);
this.scale = new Phaser.ScaleManager(this, this.width, this.height);
this.setUpRenderer();
@@ -636,6 +636,7 @@ Phaser.Game.prototype = {
this.pendingStep = true;
}
this.state.preUpdate();
this.plugins.preUpdate();
this.stage.preUpdate();
@@ -5,15 +5,15 @@
*/
/**
* The StageScaleMode object is responsible for helping you manage the scaling, resizing and alignment of your game within the browser.
* The ScaleManager object is responsible for helping you manage the scaling, resizing and alignment of your game within the browser.
*
* @class Phaser.StageScaleMode
* @class Phaser.ScaleManager
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {number} width - The native width of the game.
* @param {number} height - The native height of the game.
*/
Phaser.StageScaleMode = function (game, width, height) {
Phaser.ScaleManager = function (game, width, height) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
@@ -175,12 +175,12 @@ Phaser.StageScaleMode = function (game, width, height) {
/**
* @property {number} scaleMode - The current scaleMode.
*/
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
this.scaleMode = Phaser.ScaleManager.NO_SCALE;
/*
* @property {number} fullScreenScaleMode - Scale mode to be used in fullScreen
*/
this.fullScreenScaleMode = Phaser.StageScaleMode.NO_SCALE;
this.fullScreenScaleMode = Phaser.ScaleManager.NO_SCALE;
/**
* @property {number} _startHeight - Internal cache var. Stage height when starting the game.
@@ -228,26 +228,26 @@ Phaser.StageScaleMode = function (game, width, height) {
* @constant
* @type {number}
*/
Phaser.StageScaleMode.EXACT_FIT = 0;
Phaser.ScaleManager.EXACT_FIT = 0;
/**
* @constant
* @type {number}
*/
Phaser.StageScaleMode.NO_SCALE = 1;
Phaser.ScaleManager.NO_SCALE = 1;
/**
* @constant
* @type {number}
*/
Phaser.StageScaleMode.SHOW_ALL = 2;
Phaser.ScaleManager.SHOW_ALL = 2;
Phaser.StageScaleMode.prototype = {
Phaser.ScaleManager.prototype = {
/**
* Tries to enter the browser into full screen mode.
* Please note that this needs to be supported by the web browser and isn't the same thing as setting your game to fill the browser.
* @method Phaser.StageScaleMode#startFullScreen
* @method Phaser.ScaleManager#startFullScreen
* @param {boolean} antialias - You can toggle the anti-alias feature of the canvas before jumping in to full screen (false = retain pixel art, true = smooth art)
*/
startFullScreen: function (antialias) {
@@ -287,7 +287,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Stops full screen mode if the browser is in it.
* @method Phaser.StageScaleMode#stopFullScreen
* @method Phaser.ScaleManager#stopFullScreen
*/
stopFullScreen: function () {
@@ -308,7 +308,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Called automatically when the browser enters of leaves full screen mode.
* @method Phaser.StageScaleMode#fullScreenChange
* @method Phaser.ScaleManager#fullScreenChange
* @param {Event} event - The fullscreenchange event
* @protected
*/
@@ -318,7 +318,7 @@ Phaser.StageScaleMode.prototype = {
if (this.isFullScreen)
{
if (this.fullScreenScaleMode === Phaser.StageScaleMode.EXACT_FIT)
if (this.fullScreenScaleMode === Phaser.ScaleManager.EXACT_FIT)
{
this.game.canvas.style['width'] = '100%';
this.game.canvas.style['height'] = '100%';
@@ -331,7 +331,7 @@ Phaser.StageScaleMode.prototype = {
this.scaleFactor.x = this.game.width / this.width;
this.scaleFactor.y = this.game.height / this.height;
}
else if (this.fullScreenScaleMode === Phaser.StageScaleMode.SHOW_ALL)
else if (this.fullScreenScaleMode === Phaser.ScaleManager.SHOW_ALL)
{
this.setShowAll();
this.refresh();
@@ -357,7 +357,7 @@ Phaser.StageScaleMode.prototype = {
/**
* If you need your game to run in only one orientation you can force that to happen.
* The optional orientationImage is displayed when the game is in the incorrect orientation.
* @method Phaser.StageScaleMode#forceOrientation
* @method Phaser.ScaleManager#forceOrientation
* @param {boolean} forceLandscape - true if the game should run in landscape mode only.
* @param {boolean} [forcePortrait=false] - true if the game should run in portrait mode only.
* @param {string} [orientationImage=''] - The string of an image in the Phaser.Cache to display when this game is in the incorrect orientation.
@@ -402,7 +402,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Checks if the browser is in the correct orientation for your game (if forceLandscape or forcePortrait have been set)
* @method Phaser.StageScaleMode#checkOrientationState
* @method Phaser.ScaleManager#checkOrientationState
*/
checkOrientationState: function () {
@@ -447,7 +447,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Handle window.orientationchange events
* @method Phaser.StageScaleMode#checkOrientation
* @method Phaser.ScaleManager#checkOrientation
* @param {Event} event - The orientationchange event data.
*/
checkOrientation: function (event) {
@@ -465,7 +465,7 @@ Phaser.StageScaleMode.prototype = {
this.enterPortrait.dispatch(this.orientation, false, true);
}
if (this.scaleMode !== Phaser.StageScaleMode.NO_SCALE)
if (this.scaleMode !== Phaser.ScaleManager.NO_SCALE)
{
this.refresh();
}
@@ -474,7 +474,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Handle window.resize events
* @method Phaser.StageScaleMode#checkResize
* @method Phaser.ScaleManager#checkResize
* @param {Event} event - The resize event data.
*/
checkResize: function (event) {
@@ -499,7 +499,7 @@ Phaser.StageScaleMode.prototype = {
this.enterPortrait.dispatch(this.orientation, false, true);
}
if (this.scaleMode !== Phaser.StageScaleMode.NO_SCALE)
if (this.scaleMode !== Phaser.ScaleManager.NO_SCALE)
{
this.refresh();
}
@@ -510,7 +510,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Re-calculate scale mode and update screen size.
* @method Phaser.StageScaleMode#refresh
* @method Phaser.ScaleManager#refresh
*/
refresh: function () {
@@ -578,22 +578,22 @@ Phaser.StageScaleMode.prototype = {
}
else if (!this.isFullScreen)
{
if (this.scaleMode == Phaser.StageScaleMode.EXACT_FIT)
if (this.scaleMode == Phaser.ScaleManager.EXACT_FIT)
{
this.setExactFit();
}
else if (this.scaleMode == Phaser.StageScaleMode.SHOW_ALL)
else if (this.scaleMode == Phaser.ScaleManager.SHOW_ALL)
{
this.setShowAll();
}
}
else
{
if (this.fullScreenScaleMode == Phaser.StageScaleMode.EXACT_FIT)
if (this.fullScreenScaleMode == Phaser.ScaleManager.EXACT_FIT)
{
this.setExactFit();
}
else if (this.fullScreenScaleMode == Phaser.StageScaleMode.SHOW_ALL)
else if (this.fullScreenScaleMode == Phaser.ScaleManager.SHOW_ALL)
{
this.setShowAll();
}
@@ -608,7 +608,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Sets the canvas style width and height values based on minWidth/Height and maxWidth/Height.
* @method Phaser.StageScaleMode#setSize
* @method Phaser.ScaleManager#setSize
*/
setSize: function () {
@@ -686,7 +686,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Sets this.width equal to window.innerWidth and this.height equal to window.innerHeight
* @method Phaser.StageScaleMode#setMaximum
* @method Phaser.ScaleManager#setMaximum
*/
setMaximum: function () {
@@ -697,7 +697,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Calculates the multiplier needed to scale the game proportionally.
* @method Phaser.StageScaleMode#setShowAll
* @method Phaser.ScaleManager#setShowAll
*/
setShowAll: function () {
@@ -710,7 +710,7 @@ Phaser.StageScaleMode.prototype = {
/**
* Sets the width and height values of the canvas, no larger than the maxWidth/Height.
* @method Phaser.StageScaleMode#setExactFit
* @method Phaser.ScaleManager#setExactFit
*/
setExactFit: function () {
@@ -739,14 +739,14 @@ Phaser.StageScaleMode.prototype = {
};
Phaser.StageScaleMode.prototype.constructor = Phaser.StageScaleMode;
Phaser.ScaleManager.prototype.constructor = Phaser.ScaleManager;
/**
* @name Phaser.StageScaleMode#isFullScreen
* @name Phaser.ScaleManager#isFullScreen
* @property {boolean} isFullScreen - Returns true if the browser is in full screen mode, otherwise false.
* @readonly
*/
Object.defineProperty(Phaser.StageScaleMode.prototype, "isFullScreen", {
Object.defineProperty(Phaser.ScaleManager.prototype, "isFullScreen", {
get: function () {
@@ -757,11 +757,11 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isFullScreen", {
});
/**
* @name Phaser.StageScaleMode#isPortrait
* @name Phaser.ScaleManager#isPortrait
* @property {boolean} isPortrait - Returns true if the browser dimensions match a portrait display.
* @readonly
*/
Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", {
Object.defineProperty(Phaser.ScaleManager.prototype, "isPortrait", {
get: function () {
return this.orientation === 0 || this.orientation == 180;
@@ -770,11 +770,11 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", {
});
/**
* @name Phaser.StageScaleMode#isLandscape
* @name Phaser.ScaleManager#isLandscape
* @property {boolean} isLandscape - Returns true if the browser dimensions match a landscape display.
* @readonly
*/
Object.defineProperty(Phaser.StageScaleMode.prototype, "isLandscape", {
Object.defineProperty(Phaser.ScaleManager.prototype, "isLandscape", {
get: function () {
return this.orientation === 90 || this.orientation === -90;
+16 -14
View File
@@ -21,82 +21,84 @@ Phaser.State = function () {
/**
* @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory.
* @default
*/
this.add = null;
/**
* @property {Phaser.GameObjectCreator} make - Reference to the GameObjectCreator.
*/
this.make = null;
/**
* @property {Phaser.Camera} camera - A handy reference to world.camera.
* @default
*/
this.camera = null;
/**
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
this.cache = null;
/**
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
this.input = null;
/**
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
this.load = null;
/**
* @property {Phaser.Math} math - Reference to the math helper.
* @default
*/
this.math = null;
/**
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default
*/
this.sound = null;
/**
* @property {Phaser.ScaleManager} scale - Reference to the game scale manager.
*/
this.scale = null;
/**
* @property {Phaser.Stage} stage - Reference to the stage.
* @default
*/
this.stage = null;
/**
* @property {Phaser.TimeManager} time - Reference to game clock.
* @default
*/
this.time = null;
/**
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default
*/
this.tweens = null;
/**
* @property {Phaser.World} world - Reference to the world.
* @default
*/
this.world = null;
/**
* @property {Phaser.Particles} particles - The Particle Manager for the game. It is called during the game update loop and in turn updates any Emitters attached to it.
* @default
*/
this.particles = null;
/**
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default
* @property {Phaser.Physics.World} physics - Reference to the physics manager.
*/
this.physics = null;
/**
* @property {Phaser.RandomDataGenerator} rnd - Reference to the random data generator.
*/
this.rnd = null;
};
Phaser.State.prototype = {
+97 -11
View File
@@ -37,6 +37,18 @@ Phaser.StateManager = function (game, pendingState) {
this._pendingState = pendingState;
}
/**
* @property {boolean} _clearWorld - Clear the world when we switch state?
* @private
*/
this._clearWorld = false;
/**
* @property {boolean} _clearCache - Clear the cache when we switch state?
* @private
*/
this._clearCache = false;
/**
* @property {boolean} _created - Flag that sets if the State has been created or not.
* @private
@@ -228,7 +240,27 @@ Phaser.StateManager.prototype = {
if (typeof clearWorld === "undefined") { clearWorld = true; }
if (typeof clearCache === "undefined") { clearCache = false; }
if (this.game.isBooted === false)
if (this.checkState(key))
{
// Place the state in the queue. It will be started the next time the game loop starts.
this._pendingState = key;
this._clearWorld = clearWorld;
this._clearCache = clearCache;
if (arguments.length > 3)
{
this._args = Array.prototype.splice.call(arguments, 3);
}
// Already got a state running?
if (this.current)
{
this.onShutDownCallback.call(this.callbackContext, this.game);
}
}
/* if (this.game.isBooted === false)
{
this._pendingState = key;
@@ -251,7 +283,6 @@ Phaser.StateManager.prototype = {
this._args = [];
}
}
if (arguments.length > 3)
{
this._args = Array.prototype.splice.call(arguments, 3);
@@ -305,6 +336,7 @@ Phaser.StateManager.prototype = {
// No init? Then there was nothing to load either
this.game.loadComplete();
}
*/
},
@@ -323,6 +355,64 @@ Phaser.StateManager.prototype = {
* @param {string} key - The key of the state you want to check.
* @return {boolean} Description.
*/
preUpdate: function () {
if (this._pendingState && this.game.isBooted)
{
// Already got a state running?
if (this.current)
{
this.onShutDownCallback.call(this.callbackContext, this.game);
}
if (this._clearWorld)
{
this.game.tweens.removeAll();
this.game.world.destroy();
if (this._clearCache === true)
{
this.game.cache.destroy();
}
}
this.setCurrentState(this._pendingState);
if (this.onPreloadCallback)
{
this.game.load.reset();
this.onPreloadCallback.call(this.callbackContext, this.game);
// Is the loader empty?
if (this.game.load.totalQueuedFiles() === 0)
{
this.game.loadComplete();
}
else
{
// Start the loader going as we have something in the queue
this.game.load.start();
}
}
else
{
// No init? Then there was nothing to load either
this.game.loadComplete();
}
this._pendingState = null;
}
},
/**
* Checks if a given phaser state is valid. A State is considered valid if it has at least one of the core functions: preload, create, update or render.
*
* @method Phaser.StateManager#checkState
* @param {string} key - The key of the state you want to check.
* @return {boolean} true if the State has the required functions, otherwise false.
*/
checkState: function (key) {
if (this.states[key])
@@ -330,18 +420,13 @@ Phaser.StateManager.prototype = {
var valid = false;
if (this.states[key]['preload']) { valid = true; }
if (valid === false && this.states[key]['loadRender']) { valid = true; }
if (valid === false && this.states[key]['loadUpdate']) { valid = true; }
if (valid === false && this.states[key]['create']) { valid = true; }
if (valid === false && this.states[key]['update']) { valid = true; }
if (valid === false && this.states[key]['preRender']) { valid = true; }
if (valid === false && this.states[key]['render']) { valid = true; }
if (valid === false && this.states[key]['paused']) { valid = true; }
if (this.states[key]['create']) { valid = true; }
if (this.states[key]['update']) { valid = true; }
if (this.states[key]['render']) { valid = true; }
if (valid === false)
{
console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions.");
console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions: preload, create, update or render");
return false;
}
@@ -373,6 +458,7 @@ Phaser.StateManager.prototype = {
this.states[key].math = this.game.math;
this.states[key].sound = this.game.sound;
this.states[key].scale = this.game.scale;
this.states[key].state = this;
this.states[key].stage = this.game.stage;
this.states[key].time = this.game.time;
this.states[key].tweens = this.game.tweens;
+1 -1
View File
@@ -104,7 +104,7 @@ Phaser.Input = function (game) {
this.circle = null;
/**
* @property {Phaser.Point} scale - The scale by which all input coordinates are multiplied; calculated by the StageScaleMode. In an un-scaled game the values will be x = 1 and y = 1.
* @property {Phaser.Point} scale - The scale by which all input coordinates are multiplied; calculated by the ScaleManager. In an un-scaled game the values will be x = 1 and y = 1.
*/
this.scale = null;