mirror of
https://github.com/wassname/phaser.git
synced 2026-07-25 13:20:14 +08:00
StateManager.start can now have as many parameters as you like. The order is: start(key, clearWorld, clearCache, ...) - they are passed to State.init() (NOT create!)
This commit is contained in:
@@ -114,6 +114,7 @@ New features:
|
||||
* Key.onHold added. This event is dispatched every time the browser sends a keydown event and the key is already being held down.
|
||||
* Stage.smoothed allows you to set if sprites will be smoothed when rendered. Set to false if you're using pixel art in your game. Default is true. Works in Canvas and WebGL.
|
||||
* Sprite.smoothed and Image.smoothed allows you to set per-Sprite smoothing, perfect if you just want to keep a few sprites smoothed (or not)
|
||||
* StateManager.start can now have as many parameters as you like. The order is: start(key, clearWorld, clearCache, ...) - they are passed to State.init() (NOT create!)
|
||||
|
||||
|
||||
Updates:
|
||||
|
||||
+1734
-531
File diff suppressed because it is too large
Load Diff
Vendored
+17
-16
File diff suppressed because one or more lines are too long
@@ -0,0 +1,92 @@
|
||||
var BasicGame = {};
|
||||
|
||||
BasicGame.Boot = function (game) {
|
||||
|
||||
this.a;
|
||||
this.b;
|
||||
|
||||
};
|
||||
|
||||
BasicGame.Boot.prototype = {
|
||||
|
||||
init: function (a, b) {
|
||||
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
console.log('Boot is alive');
|
||||
console.log('A: ', this.a);
|
||||
console.log('B: ', this.b);
|
||||
|
||||
},
|
||||
|
||||
create: function () {
|
||||
|
||||
this.game.state.start('Preloader', true, false, this.a, this.b);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
BasicGame.Preloader = function (game) {
|
||||
|
||||
this.a;
|
||||
this.b;
|
||||
|
||||
};
|
||||
|
||||
BasicGame.Preloader.prototype = {
|
||||
|
||||
init: function (a, b) {
|
||||
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
console.log('Preloader is alive');
|
||||
console.log('A: ', this.a);
|
||||
console.log('B: ', this.b);
|
||||
|
||||
},
|
||||
|
||||
create: function () {
|
||||
|
||||
this.game.state.start('MainMenu', true, false, this.a, this.b);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
BasicGame.MainMenu = function (game) {
|
||||
|
||||
this.a;
|
||||
this.b;
|
||||
|
||||
};
|
||||
|
||||
BasicGame.MainMenu.prototype = {
|
||||
|
||||
init: function (a, b) {
|
||||
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
|
||||
},
|
||||
|
||||
create: function () {
|
||||
|
||||
this.game.stage.backgroundColor = 0x2d2d2d;
|
||||
|
||||
console.log('Main Menu is alive');
|
||||
console.log('A: ', this.a);
|
||||
console.log('B: ', this.b);
|
||||
console.log(this.game);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var game = new Phaser.Game(1024, 768, Phaser.AUTO, 'phaser-example');
|
||||
|
||||
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');
|
||||
@@ -43,6 +43,12 @@ Phaser.StateManager = function (game, pendingState) {
|
||||
*/
|
||||
this._created = false;
|
||||
|
||||
/**
|
||||
* @property {array} _args - Temporary container when you pass vars from one State to another.
|
||||
* @private
|
||||
*/
|
||||
this._args = [];
|
||||
|
||||
/**
|
||||
* @property {string} current - The current active State object (defaults to null).
|
||||
*/
|
||||
@@ -215,6 +221,7 @@ Phaser.StateManager.prototype = {
|
||||
* @param {string} key - The key of the state you want to start.
|
||||
* @param {boolean} [clearWorld=true] - Clear everything in the world? This clears the World display list fully (but not the Stage, so if you've added your own objects to the Stage they will need managing directly)
|
||||
* @param {boolean} [clearCache=false] - Clear the Game.Cache? This purges out all loaded assets. The default is false and you must have clearWorld=true if you want to clearCache as well.
|
||||
* @param {...*} parameter - Additional parameters that will be passed to the State.init function (if it has one).
|
||||
*/
|
||||
start: function (key, clearWorld, clearCache) {
|
||||
|
||||
@@ -224,8 +231,34 @@ Phaser.StateManager.prototype = {
|
||||
if (this.game.isBooted === false)
|
||||
{
|
||||
this._pendingState = key;
|
||||
|
||||
if (arguments.length > 3)
|
||||
{
|
||||
this._args = Array.prototype.splice.call(arguments, 3);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we still have a _pendingState it's left over from game boot, so glob the args
|
||||
if (this._pendingState)
|
||||
{
|
||||
this._pendingState = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._args = [];
|
||||
}
|
||||
}
|
||||
|
||||
console.log('state start', key);
|
||||
console.log(arguments);
|
||||
|
||||
if (arguments.length > 3)
|
||||
{
|
||||
this._args = Array.prototype.splice.call(arguments, 3);
|
||||
}
|
||||
|
||||
if (this.checkState(key) === false)
|
||||
{
|
||||
@@ -384,7 +417,7 @@ Phaser.StateManager.prototype = {
|
||||
this.current = key;
|
||||
this._created = false;
|
||||
|
||||
this.onInitCallback.call(this.callbackContext, this.game);
|
||||
this.onInitCallback.apply(this.callbackContext, this._args);
|
||||
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user