Skip to content

Commit cfb1826

Browse files
committed
Added new test feature
1 parent 18a6cf8 commit cfb1826

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

src/scene/ScenePlugin.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,56 @@ var ScenePlugin = new Class({
7070
*/
7171
this.manager = scene.sys.game.scene;
7272

73+
/**
74+
* Transition elapsed timer.
75+
*
76+
* @name Phaser.Scenes.ScenePlugin#_elapsed
77+
* @type {integer}
78+
* @private
79+
* @since 3.4.1
80+
*/
81+
this._elapsed = 0;
82+
83+
/**
84+
* Transition elapsed timer.
85+
*
86+
* @name Phaser.Scenes.ScenePlugin#_target
87+
* @type {Phaser.Scenes.Scene}
88+
* @private
89+
* @since 3.4.1
90+
*/
91+
this._target;
92+
93+
/**
94+
* Transition duration.
95+
*
96+
* @name Phaser.Scenes.ScenePlugin#_duration
97+
* @type {integer}
98+
* @private
99+
* @since 3.4.1
100+
*/
101+
this._duration = 0;
102+
103+
/**
104+
* Transition callback.
105+
*
106+
* @name Phaser.Scenes.ScenePlugin#_onUpdate
107+
* @type {function}
108+
* @private
109+
* @since 3.4.1
110+
*/
111+
this._onUpdate;
112+
113+
/**
114+
* Transition callback.
115+
*
116+
* @name Phaser.Scenes.ScenePlugin#_onUpdateScope
117+
* @type {object}
118+
* @private
119+
* @since 3.4.1
120+
*/
121+
this._onUpdateScope;
122+
73123
scene.sys.events.on('start', this.pluginStart, this);
74124
},
75125

@@ -147,6 +197,78 @@ var ScenePlugin = new Class({
147197
return this;
148198
},
149199

200+
/**
201+
* BETA ( + fadeTo )
202+
* Fire start and complete events in target Scene + this Scene.
203+
* const leaving
204+
*
205+
* @method Phaser.Scenes.ScenePlugin#transition
206+
* @since 3.4.1
207+
*
208+
* @param {string} key - The Scene key to transition to.
209+
* @param {integer} [duration=1000] - The duration, in ms, for the transition to last.
210+
* @param {boolean} [moveAbove=false] - More the target Scene to be above this one before the transition starts. `false` means no change to the Scene display order.
211+
* @param {function} [callback] - This callback is invoked every frame for the duration of the transition.
212+
* @param {any} [context] - The context in which the callback is invoked.
213+
*
214+
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
215+
*/
216+
transition: function (key, duration, moveAbove, callback, context)
217+
{
218+
if (duration === undefined) { duration = 1000; }
219+
220+
var target = this.get(key);
221+
222+
if (target && this.settings.status === CONST.RUNNING && this._duration === 0)
223+
{
224+
this._elapsed = 0;
225+
this._target = target;
226+
this._duration = duration;
227+
this._onUpdate = callback;
228+
this._onUpdateScope = context;
229+
230+
// Do it via the manager?
231+
// this.manager.transition(from, to, duration, moveAbove, data);
232+
233+
this.manager.start(key);
234+
235+
// Needs storing in manager data, as fires too early here
236+
target.sys.events.emit('transitionstart', this.scene, duration);
237+
238+
this.systems.events.on('postupdate', this.step, this);
239+
}
240+
241+
return this;
242+
},
243+
244+
/**
245+
* A single game step. This is only called if the parent Scene is transitioning
246+
* out to another Scene.
247+
*
248+
* @method Phaser.Scenes.ScenePlugin#step
249+
* @private
250+
* @since 3.4.1
251+
*
252+
* @param {number} time - [description]
253+
* @param {number} delta - [description]
254+
*/
255+
step: function (time, delta)
256+
{
257+
this._elapsed += delta;
258+
259+
if (this._elapsed >= this._duration)
260+
{
261+
// Stop the step
262+
this.systems.events.off('postupdate', this.step, this);
263+
264+
// Notify target scene
265+
this._target.sys.events.emit('transitioncomplete', this.scene);
266+
267+
// Stop this Scene
268+
this.manager.stop(this.key);
269+
}
270+
},
271+
150272
/**
151273
* Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set.
152274
*
@@ -606,9 +728,12 @@ var ScenePlugin = new Class({
606728
*/
607729
shutdown: function ()
608730
{
731+
this._duration = 0;
732+
609733
var eventEmitter = this.systems.events;
610734

611735
eventEmitter.off('shutdown', this.shutdown, this);
736+
eventEmitter.off('postupdate', this.step, this);
612737
},
613738

614739
/**

0 commit comments

Comments
 (0)