mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
If you called StateManager.start from within a states init
method which also had a preload
method it would fail to start the next State.
This commit is contained in:
parent
756561920f
commit
d68ed61999
2 changed files with 55 additions and 3 deletions
|
@ -77,6 +77,7 @@ Version 2.1.2 - "Whitebridge" - in development
|
|||
|
||||
* StateManager.unlink will null all State-level Phaser properties, such as `game`, `add`, etc. Useful if you never need to return to the State again.
|
||||
* Cache.removeImage has a new parameter: `removeFromPixi` which is `true` by default. It will remove the image from the Pixi BaseTextureCache as well as from the Phaser Cache. Set to false if you don't want the Pixi cache touched.
|
||||
* Group.ignoreDestroy boolean will bail out early from any call to `Group.destroy`. Handy if you need to create a global Group that persists across States.
|
||||
|
||||
|
||||
### Updates
|
||||
|
@ -88,6 +89,7 @@ Version 2.1.2 - "Whitebridge" - in development
|
|||
### Bug Fixes
|
||||
|
||||
* If Game Objects change their frame, such as with an animated Sprite, and the change goes from a previously trimmed frame to a non-trimmed (full size) one, then the previous trim values were still left active, causing it to glitch (thanks stupot)
|
||||
* If you called StateManager.start from within a states `init` method which also had a `preload` method it would fail to start the next State.
|
||||
|
||||
|
||||
For details about changes made in previous versions of Phaser see the full Change Log at https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md
|
||||
|
|
|
@ -142,6 +142,8 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
boot: function () {
|
||||
|
||||
console.log('StateManager boot');
|
||||
|
||||
this.game.onPause.add(this.pause, this);
|
||||
this.game.onResume.add(this.resume, this);
|
||||
this.game.load.onLoadComplete.add(this.loadComplete, this);
|
||||
|
@ -151,7 +153,8 @@ Phaser.StateManager.prototype = {
|
|||
if (typeof this._pendingState === 'string')
|
||||
{
|
||||
// State was already added, so just start it
|
||||
this.start(this._pendingState, false, false);
|
||||
console.log('StateManager boot => waiting for preUpdate', this._pendingState);
|
||||
// this.start(this._pendingState, false, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -250,12 +253,17 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
start: function (key, clearWorld, clearCache) {
|
||||
|
||||
console.log('-----------------------------------------------------------------------------------------');
|
||||
console.log('START:', key);
|
||||
|
||||
if (typeof clearWorld === "undefined") { clearWorld = true; }
|
||||
if (typeof clearCache === "undefined") { clearCache = false; }
|
||||
|
||||
if (this.checkState(key))
|
||||
{
|
||||
// Place the state in the queue. It will be started the next time the game loop starts.
|
||||
console.log('set to pending', key);
|
||||
|
||||
this._pendingState = key;
|
||||
this._clearWorld = clearWorld;
|
||||
this._clearCache = clearCache;
|
||||
|
@ -310,32 +318,50 @@ Phaser.StateManager.prototype = {
|
|||
|
||||
if (this._pendingState && this.game.isBooted)
|
||||
{
|
||||
console.log('preUpdate - has pending:', this._pendingState, 'current:', this.current);
|
||||
|
||||
// Already got a state running?
|
||||
this.clearCurrentState();
|
||||
|
||||
this.setCurrentState(this._pendingState);
|
||||
|
||||
this._pendingState = null;
|
||||
if (this.current !== this._pendingState)
|
||||
{
|
||||
console.log('-> init called StateManager.start(', this._pendingState, ') so bail out');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._pendingState = null;
|
||||
console.log('pending nulled');
|
||||
}
|
||||
|
||||
// If StateManager.start has been called from the init of a State that ALSO has a preload, then
|
||||
// onPreloadCallback will be set, but must be ignored
|
||||
if (this.onPreloadCallback)
|
||||
{
|
||||
console.log('-> preload (', this.current, ')');
|
||||
|
||||
this.game.load.reset();
|
||||
this.onPreloadCallback.call(this.callbackContext, this.game);
|
||||
|
||||
// Is the loader empty?
|
||||
if (this.game.load.totalQueuedFiles() === 0 && this.game.load.totalQueuedPacks() === 0)
|
||||
{
|
||||
console.log('loadComplete from empty preloader', this.current);
|
||||
this.loadComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Start the loader going as we have something in the queue
|
||||
console.log('load start', this.current);
|
||||
this.game.load.start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No init? Then there was nothing to load either
|
||||
console.log('loadComplete from no preloader', this.current);
|
||||
this.loadComplete();
|
||||
}
|
||||
}
|
||||
|
@ -350,10 +376,15 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
clearCurrentState: function () {
|
||||
|
||||
console.log('clearCurrentState', this.current);
|
||||
|
||||
if (this.current)
|
||||
{
|
||||
console.log('removing all', this.current);
|
||||
|
||||
if (this.onShutDownCallback)
|
||||
{
|
||||
console.log('-> shutdown (', this.current, ')');
|
||||
this.onShutDownCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
|
||||
|
@ -396,6 +427,8 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
checkState: function (key) {
|
||||
|
||||
console.log('checking', key);
|
||||
|
||||
if (this.states[key])
|
||||
{
|
||||
var valid = false;
|
||||
|
@ -493,6 +526,8 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
setCurrentState: function (key) {
|
||||
|
||||
console.log('setCurrentState', key);
|
||||
|
||||
this.callbackContext = this.states[key];
|
||||
|
||||
this.link(key);
|
||||
|
@ -518,9 +553,21 @@ Phaser.StateManager.prototype = {
|
|||
this.current = key;
|
||||
this._created = false;
|
||||
|
||||
// At this point key and pendingState should equal each other
|
||||
console.log('-> init (', key, ')', this._pendingState);
|
||||
|
||||
this.onInitCallback.apply(this.callbackContext, this._args);
|
||||
|
||||
this._args = [];
|
||||
// If they no longer do then the init callback hit StateManager.start
|
||||
if (key !== this._pendingState)
|
||||
{
|
||||
// console.log('-> init called StateManager.start(', this._pendingState, ')');
|
||||
// this.onPreloadCallback = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._args = [];
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
@ -541,8 +588,11 @@ Phaser.StateManager.prototype = {
|
|||
*/
|
||||
loadComplete: function () {
|
||||
|
||||
console.log('loadComplete');
|
||||
|
||||
if (this._created === false && this.onCreateCallback)
|
||||
{
|
||||
console.log('-> create (', this.current, ')');
|
||||
this._created = true;
|
||||
this.onCreateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue