Skip to content

Commit b779165

Browse files
committed
Added Scene Transition Events
1 parent a151a02 commit b779165

9 files changed

Lines changed: 108 additions & 9 deletions

src/scene/SceneManager.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var Class = require('../utils/Class');
88
var CONST = require('./const');
9+
var Events = require('./events');
910
var GetValue = require('../utils/object/GetValue');
1011
var NOOP = require('../utils/NOOP');
1112
var Scene = require('./Scene');
@@ -439,6 +440,7 @@ var SceneManager = new Class({
439440
*
440441
* @method Phaser.Scenes.SceneManager#bootScene
441442
* @private
443+
* @fires Phaser.Scenes.Events#TRANSITION_INIT
442444
* @since 3.0.0
443445
*
444446
* @param {Phaser.Scene} scene - The Scene to boot.
@@ -456,7 +458,7 @@ var SceneManager = new Class({
456458

457459
if (settings.isTransition)
458460
{
459-
sys.events.emit('transitioninit', settings.transitionFrom, settings.transitionDuration);
461+
sys.events.emit(Events.TRANSITION_INIT, settings.transitionFrom, settings.transitionDuration);
460462
}
461463
}
462464

@@ -589,6 +591,7 @@ var SceneManager = new Class({
589591
*
590592
* @method Phaser.Scenes.SceneManager#create
591593
* @private
594+
* @fires Phaser.Scenes.Events#TRANSITION_INIT
592595
* @since 3.0.0
593596
*
594597
* @param {Phaser.Scene} scene - The Scene to create.
@@ -607,7 +610,7 @@ var SceneManager = new Class({
607610

608611
if (settings.isTransition)
609612
{
610-
sys.events.emit('transitionstart', settings.transitionFrom, settings.transitionDuration);
613+
sys.events.emit(Events.TRANSITION_START, settings.transitionFrom, settings.transitionDuration);
611614
}
612615

613616
// If the Scene has an update function we'll set it now, otherwise it'll remain as NOOP

src/scene/ScenePlugin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
var Clamp = require('../math/Clamp');
88
var Class = require('../utils/Class');
9+
var Events = require('./events');
910
var GetFastValue = require('../utils/object/GetFastValue');
1011
var PluginCache = require('../plugins/PluginCache');
1112

@@ -251,7 +252,7 @@ var ScenePlugin = new Class({
251252
*
252253
* This Scene can either be sent to sleep at the end of the transition, or stopped. The default is to stop.
253254
*
254-
* There are also 5 transition related events: This scene will emit the event `transitionto` when
255+
* There are also 5 transition related events: This scene will emit the event `transitionout` when
255256
* the transition begins, which is typically the frame after calling this method.
256257
*
257258
* The target Scene will emit the event `transitioninit` when that Scene's `init` method is called.
@@ -270,6 +271,7 @@ var ScenePlugin = new Class({
270271
* override this understand that until the target Scene completes it might never be unlocked for input events.
271272
*
272273
* @method Phaser.Scenes.ScenePlugin#transition
274+
* @fires Phaser.Scenes.Events#TRANSITION_OUT
273275
* @since 3.5.0
274276
*
275277
* @param {Phaser.Scenes.ScenePlugin.SceneTransitionConfig} config - The transition configuration object.
@@ -334,7 +336,7 @@ var ScenePlugin = new Class({
334336
this.manager.start(key, GetFastValue(config, 'data'));
335337
}
336338

337-
this.systems.events.emit('transitionout', target, duration);
339+
this.systems.events.emit(Events.TRANSITION_OUT, target, duration);
338340

339341
this.systems.events.on('update', this.step, this);
340342

@@ -396,6 +398,7 @@ var ScenePlugin = new Class({
396398
*
397399
* @method Phaser.Scenes.ScenePlugin#transitionComplete
398400
* @private
401+
* @fires Phaser.Scenes.Events#TRANSITION_COMPLETE
399402
* @since 3.5.0
400403
*/
401404
transitionComplete: function ()
@@ -407,7 +410,7 @@ var ScenePlugin = new Class({
407410
this.systems.events.off('update', this.step, this);
408411

409412
// Notify target scene
410-
targetSys.events.emit('transitioncomplete', this.scene);
413+
targetSys.events.emit(Events.TRANSITION_COMPLETE, this.scene);
411414

412415
// Clear target scene settings
413416
targetSettings.isTransition = false;

src/scene/Systems.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ var Systems = new Class({
519519

520520
if (settings.isTransition)
521521
{
522-
this.events.emit('transitionwake', settings.transitionFrom, settings.transitionDuration);
522+
this.events.emit(Events.TRANSITION_WAKE, settings.transitionFrom, settings.transitionDuration);
523523
}
524524

525525
return this;

src/scene/events/TRANSITION_COMPLETE_EVENT.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@
77
/**
88
* The Scene Transition Complete Event.
99
*
10-
* This event is dispatched by a Scene when the Scene Transition process completes.
10+
* This event is dispatched by the Target Scene of a transition.
11+
*
12+
* It happens when the transition process has completed. This occurs when the duration timer equals or exceeds the duration
13+
* of the transition.
1114
*
1215
* Listen to it from a Scene using `this.scene.events.on('transitioncomplete', listener)`.
1316
*
17+
* The Scene Transition event flow is as follows:
18+
*
19+
* 1) [TRANSITION_OUT]{Phaser.Scenes.Events#TRANSITION_OUT} - the Scene that started the transition will emit this event.
20+
* 2) [TRANSITION_INIT]{Phaser.Scenes.Events#TRANSITION_INIT} - the Target Scene will emit this event if it has an `init` method.
21+
* 3a) [TRANSITION_START]{Phaser.Scenes.Events#TRANSITION_START} - the Target Scene will emit this event after its `create` method is called, OR ...
22+
* 3b) [TRANSITION_WAKE]{Phaser.Scenes.Events#TRANSITION_WAKE} - the Target Scene will emit this event if it was asleep and has been woken-up to be transitioned to.
23+
* 4) [TRANSITION_COMPLETE]{Phaser.Scenes.Events#TRANSITION_COMPLETE} - the Target Scene will emit this event when the transition finishes.
24+
*
1425
* @event Phaser.Scenes.Events#TRANSITION_COMPLETE
1526
*
1627
* @param {Phaser.Scene} scene -The Scene on which the transitioned completed.

src/scene/events/TRANSITION_INIT_EVENT.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@
77
/**
88
* The Scene Transition Init Event.
99
*
10-
* This event is dispatched by a Scene during the Scene Transition process.
10+
* This event is dispatched by the Target Scene of a transition.
11+
*
12+
* It happens immediately after the `Scene.init` method is called. If the Scene does not have an `init` method,
13+
* this event is not dispatched.
1114
*
1215
* Listen to it from a Scene using `this.scene.events.on('transitioninit', listener)`.
1316
*
17+
* The Scene Transition event flow is as follows:
18+
*
19+
* 1) [TRANSITION_OUT]{Phaser.Scenes.Events#TRANSITION_OUT} - the Scene that started the transition will emit this event.
20+
* 2) [TRANSITION_INIT]{Phaser.Scenes.Events#TRANSITION_INIT} - the Target Scene will emit this event if it has an `init` method.
21+
* 3a) [TRANSITION_START]{Phaser.Scenes.Events#TRANSITION_START} - the Target Scene will emit this event after its `create` method is called, OR ...
22+
* 3b) [TRANSITION_WAKE]{Phaser.Scenes.Events#TRANSITION_WAKE} - the Target Scene will emit this event if it was asleep and has been woken-up to be transitioned to.
23+
* 4) [TRANSITION_COMPLETE]{Phaser.Scenes.Events#TRANSITION_COMPLETE} - the Target Scene will emit this event when the transition finishes.
24+
*
1425
* @event Phaser.Scenes.Events#TRANSITION_INIT
1526
*
1627
* @param {Phaser.Scene} from - A reference to the Scene that is being transitioned from.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Transition Out Event.
9+
*
10+
* This event is dispatched by a Scene when it initiates a transition to another Scene.
11+
*
12+
* Listen to it from a Scene using `this.scene.events.on('transitionout', listener)`.
13+
*
14+
* The Scene Transition event flow is as follows:
15+
*
16+
* 1) [TRANSITION_OUT]{Phaser.Scenes.Events#TRANSITION_OUT} - the Scene that started the transition will emit this event.
17+
* 2) [TRANSITION_INIT]{Phaser.Scenes.Events#TRANSITION_INIT} - the Target Scene will emit this event if it has an `init` method.
18+
* 3a) [TRANSITION_START]{Phaser.Scenes.Events#TRANSITION_START} - the Target Scene will emit this event after its `create` method is called, OR ...
19+
* 3b) [TRANSITION_WAKE]{Phaser.Scenes.Events#TRANSITION_WAKE} - the Target Scene will emit this event if it was asleep and has been woken-up to be transitioned to.
20+
* 4) [TRANSITION_COMPLETE]{Phaser.Scenes.Events#TRANSITION_COMPLETE} - the Target Scene will emit this event when the transition finishes.
21+
*
22+
* @event Phaser.Scenes.Events#TRANSITION_OUT
23+
*
24+
* @param {Phaser.Scene} target - A reference to the Scene that is being transitioned to.
25+
* @param {number} duration - The duration of the transition in ms.
26+
*/
27+
module.exports = 'transitionout';

src/scene/events/TRANSITION_START_EVENT.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@
77
/**
88
* The Scene Transition Start Event.
99
*
10-
* This event is dispatched by a Scene during the Scene Transition process.
10+
* This event is dispatched by the Target Scene of a transition, only if that Scene was not asleep.
11+
*
12+
* It happens immediately after the `Scene.create` method is called. If the Scene does not have a `create` method,
13+
* this event is dispatched anyway.
14+
*
15+
* If the Target Scene was sleeping then the [TRANSITION_WAKE]{Phaser.Scenes.Events#TRANSITION_WAKE} event is
16+
* dispatched instead of this event.
1117
*
1218
* Listen to it from a Scene using `this.scene.events.on('transitionstart', listener)`.
1319
*
20+
* The Scene Transition event flow is as follows:
21+
*
22+
* 1) [TRANSITION_OUT]{Phaser.Scenes.Events#TRANSITION_OUT} - the Scene that started the transition will emit this event.
23+
* 2) [TRANSITION_INIT]{Phaser.Scenes.Events#TRANSITION_INIT} - the Target Scene will emit this event if it has an `init` method.
24+
* 3a) [TRANSITION_START]{Phaser.Scenes.Events#TRANSITION_START} - the Target Scene will emit this event after its `create` method is called, OR ...
25+
* 3b) [TRANSITION_WAKE]{Phaser.Scenes.Events#TRANSITION_WAKE} - the Target Scene will emit this event if it was asleep and has been woken-up to be transitioned to.
26+
* 4) [TRANSITION_COMPLETE]{Phaser.Scenes.Events#TRANSITION_COMPLETE} - the Target Scene will emit this event when the transition finishes.
27+
*
1428
* @event Phaser.Scenes.Events#TRANSITION_START
1529
*
1630
* @param {Phaser.Scene} from - A reference to the Scene that is being transitioned from.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2019 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
/**
8+
* The Scene Transition Wake Event.
9+
*
10+
* This event is dispatched by the Target Scene of a transition, only if that Scene was asleep before
11+
* the transition began. If the Scene was not asleep the [TRANSITION_START]{Phaser.Scenes.Events#TRANSITION_START} event is dispatched instead.
12+
*
13+
* Listen to it from a Scene using `this.scene.events.on('transitionwake', listener)`.
14+
*
15+
* The Scene Transition event flow is as follows:
16+
*
17+
* 1) [TRANSITION_OUT]{Phaser.Scenes.Events#TRANSITION_OUT} - the Scene that started the transition will emit this event.
18+
* 2) [TRANSITION_INIT]{Phaser.Scenes.Events#TRANSITION_INIT} - the Target Scene will emit this event if it has an `init` method.
19+
* 3a) [TRANSITION_START]{Phaser.Scenes.Events#TRANSITION_START} - the Target Scene will emit this event after its `create` method is called, OR ...
20+
* 3b) [TRANSITION_WAKE]{Phaser.Scenes.Events#TRANSITION_WAKE} - the Target Scene will emit this event if it was asleep and has been woken-up to be transitioned to.
21+
* 4) [TRANSITION_COMPLETE]{Phaser.Scenes.Events#TRANSITION_COMPLETE} - the Target Scene will emit this event when the transition finishes.
22+
*
23+
* @event Phaser.Scenes.Events#TRANSITION_WAKE
24+
*
25+
* @param {Phaser.Scene} from - A reference to the Scene that is being transitioned from.
26+
* @param {number} duration - The duration of the transition in ms.
27+
*/
28+
module.exports = 'transitionwake';

src/scene/events/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ module.exports = {
2323
START: require('./START_EVENT'),
2424
TRANSITION_COMPLETE: require('./TRANSITION_COMPLETE_EVENT'),
2525
TRANSITION_INIT: require('./TRANSITION_INIT_EVENT'),
26+
TRANSITION_OUT: require('./TRANSITION_OUT_EVENT'),
2627
TRANSITION_START: require('./TRANSITION_START_EVENT'),
28+
TRANSITION_WAKE: require('./TRANSITION_WAKE_EVENT'),
2729
UPDATE: require('./UPDATE_EVENT'),
2830
WAKE: require('./WAKE_EVENT')
2931

0 commit comments

Comments
 (0)