mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
Sorted out the scene event order, targets and callbacks
This commit is contained in:
parent
cfb1826da9
commit
616d17fa83
3 changed files with 62 additions and 13 deletions
|
@ -429,16 +429,28 @@ var SceneManager = new Class({
|
|||
*/
|
||||
bootScene: function (scene)
|
||||
{
|
||||
var sys = scene.sys;
|
||||
var settings = sys.settings;
|
||||
|
||||
if (scene.init)
|
||||
{
|
||||
scene.init.call(scene, scene.sys.settings.data);
|
||||
scene.init.call(scene, settings.data);
|
||||
|
||||
if (settings.isTransition && sys.events.listenerCount('transitionstart') > 0)
|
||||
{
|
||||
// There are listeners waiting for the event after 'init' has run, so emit it
|
||||
sys.events.emit('transitionstart', settings.transitionFrom);
|
||||
|
||||
settings.isTransition = false;
|
||||
settings.transitionFrom = null;
|
||||
}
|
||||
}
|
||||
|
||||
var loader;
|
||||
|
||||
if (scene.sys.load)
|
||||
if (sys.load)
|
||||
{
|
||||
loader = scene.sys.load;
|
||||
loader = sys.load;
|
||||
|
||||
loader.reset();
|
||||
}
|
||||
|
@ -454,7 +466,7 @@ var SceneManager = new Class({
|
|||
}
|
||||
else
|
||||
{
|
||||
scene.sys.settings.status = CONST.LOADING;
|
||||
settings.status = CONST.LOADING;
|
||||
|
||||
// Start the loader going as we have something in the queue
|
||||
loader.once('complete', this.loadComplete, this);
|
||||
|
@ -583,14 +595,26 @@ var SceneManager = new Class({
|
|||
*/
|
||||
create: function (scene)
|
||||
{
|
||||
var sys = scene.sys;
|
||||
var settings = sys.settings;
|
||||
|
||||
if (scene.create)
|
||||
{
|
||||
scene.sys.settings.status = CONST.CREATING;
|
||||
|
||||
scene.create.call(scene, scene.sys.settings.data);
|
||||
|
||||
if (settings.isTransition && sys.events.listenerCount('transitionstart') > 0)
|
||||
{
|
||||
// There are listeners waiting for the event after 'init' has run, so emit it
|
||||
sys.events.emit('transitionstart', settings.transitionFrom);
|
||||
|
||||
settings.isTransition = false;
|
||||
settings.transitionFrom = null;
|
||||
}
|
||||
}
|
||||
|
||||
scene.sys.settings.status = CONST.RUNNING;
|
||||
settings.status = CONST.RUNNING;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -84,11 +84,11 @@ var ScenePlugin = new Class({
|
|||
* Transition elapsed timer.
|
||||
*
|
||||
* @name Phaser.Scenes.ScenePlugin#_target
|
||||
* @type {Phaser.Scenes.Scene}
|
||||
* @type {?Phaser.Scenes.Scene}
|
||||
* @private
|
||||
* @since 3.4.1
|
||||
*/
|
||||
this._target;
|
||||
this._target = null;
|
||||
|
||||
/**
|
||||
* Transition duration.
|
||||
|
@ -216,10 +216,17 @@ var ScenePlugin = new Class({
|
|||
transition: function (key, duration, moveAbove, callback, context)
|
||||
{
|
||||
if (duration === undefined) { duration = 1000; }
|
||||
if (moveAbove === undefined) { moveAbove = false; }
|
||||
if (context === undefined) { context = this.scene; }
|
||||
|
||||
var target = this.get(key);
|
||||
|
||||
if (target && this.settings.status === CONST.RUNNING && this._duration === 0)
|
||||
if (
|
||||
target &&
|
||||
!target.sys.isActive() &&
|
||||
!target.sys.settings.isTransition &&
|
||||
this.settings.status === CONST.RUNNING &&
|
||||
!this._target)
|
||||
{
|
||||
this._elapsed = 0;
|
||||
this._target = target;
|
||||
|
@ -227,13 +234,15 @@ var ScenePlugin = new Class({
|
|||
this._onUpdate = callback;
|
||||
this._onUpdateScope = context;
|
||||
|
||||
// Do it via the manager?
|
||||
// this.manager.transition(from, to, duration, moveAbove, data);
|
||||
target.sys.settings.isTransition = true;
|
||||
target.sys.settings.transitionFrom = this.scene;
|
||||
|
||||
this.manager.start(key);
|
||||
|
||||
// Needs storing in manager data, as fires too early here
|
||||
target.sys.events.emit('transitionstart', this.scene, duration);
|
||||
if (moveAbove)
|
||||
{
|
||||
this.manager.moveAbove(this.key, key);
|
||||
}
|
||||
|
||||
this.systems.events.on('postupdate', this.step, this);
|
||||
}
|
||||
|
@ -256,6 +265,11 @@ var ScenePlugin = new Class({
|
|||
{
|
||||
this._elapsed += delta;
|
||||
|
||||
if (this._onUpdate)
|
||||
{
|
||||
this._onUpdate.call(this._onUpdateScope, time, delta);
|
||||
}
|
||||
|
||||
if (this._elapsed >= this._duration)
|
||||
{
|
||||
// Stop the step
|
||||
|
@ -264,6 +278,10 @@ var ScenePlugin = new Class({
|
|||
// Notify target scene
|
||||
this._target.sys.events.emit('transitioncomplete', this.scene);
|
||||
|
||||
// Clear the target out
|
||||
this._target.sys.settings.isTransition = false;
|
||||
this._target.sys.settings.transitionFrom = null;
|
||||
|
||||
// Stop this Scene
|
||||
this.manager.stop(this.key);
|
||||
}
|
||||
|
@ -728,7 +746,9 @@ var ScenePlugin = new Class({
|
|||
*/
|
||||
shutdown: function ()
|
||||
{
|
||||
this._duration = 0;
|
||||
this._target = null;
|
||||
this._onUpdate = null;
|
||||
this._onUpdateScope = null;
|
||||
|
||||
var eventEmitter = this.systems.events;
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ var InjectionMap = require('./InjectionMap');
|
|||
* @property {boolean} active - [description]
|
||||
* @property {boolean} visible - [description]
|
||||
* @property {boolean} isBooted - [description]
|
||||
* @property {boolean} isTransition - [description]
|
||||
* @property {?Phaser.Scene} transitionFrom - [description]
|
||||
* @property {object} data - [description]
|
||||
* @property {(false|LoaderFileObject[])} files - [description]
|
||||
* @property {?(InputJSONCameraObject|InputJSONCameraObject[])} cameras - [description]
|
||||
|
@ -77,6 +79,9 @@ var Settings = {
|
|||
|
||||
isBooted: false,
|
||||
|
||||
isTransition: false,
|
||||
transitionFrom: null,
|
||||
|
||||
// Loader payload array
|
||||
|
||||
data: {},
|
||||
|
|
Loading…
Reference in a new issue