forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScenePlugin.js
More file actions
1004 lines (876 loc) · 28.4 KB
/
Copy pathScenePlugin.js
File metadata and controls
1004 lines (876 loc) · 28.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Clamp = require('../math/Clamp');
var Class = require('../utils/Class');
var Events = require('./events');
var GetFastValue = require('../utils/object/GetFastValue');
var PluginCache = require('../plugins/PluginCache');
/**
* @classdesc
* A proxy class to the Global Scene Manager.
*
* @class ScenePlugin
* @memberof Phaser.Scenes
* @constructor
* @since 3.0.0
*
* @param {Phaser.Scene} scene - The Scene that this ScenePlugin belongs to.
*/
var ScenePlugin = new Class({
initialize:
function ScenePlugin (scene)
{
/**
* The Scene that this ScenePlugin belongs to.
*
* @name Phaser.Scenes.ScenePlugin#scene
* @type {Phaser.Scene}
* @since 3.0.0
*/
this.scene = scene;
/**
* The Scene Systems instance of the Scene that this ScenePlugin belongs to.
*
* @name Phaser.Scenes.ScenePlugin#systems
* @type {Phaser.Scenes.Systems}
* @since 3.0.0
*/
this.systems = scene.sys;
/**
* The settings of the Scene this ScenePlugin belongs to.
*
* @name Phaser.Scenes.ScenePlugin#settings
* @type {Phaser.Types.Scenes.SettingsObject}
* @since 3.0.0
*/
this.settings = scene.sys.settings;
/**
* The key of the Scene this ScenePlugin belongs to.
*
* @name Phaser.Scenes.ScenePlugin#key
* @type {string}
* @since 3.0.0
*/
this.key = scene.sys.settings.key;
/**
* The Game's SceneManager.
*
* @name Phaser.Scenes.ScenePlugin#manager
* @type {Phaser.Scenes.SceneManager}
* @since 3.0.0
*/
this.manager = scene.sys.game.scene;
/**
* If this Scene is currently transitioning to another, this holds
* the current percentage of the transition progress, between 0 and 1.
*
* @name Phaser.Scenes.ScenePlugin#transitionProgress
* @type {number}
* @since 3.5.0
*/
this.transitionProgress = 0;
/**
* Transition elapsed timer.
*
* @name Phaser.Scenes.ScenePlugin#_elapsed
* @type {number}
* @private
* @since 3.5.0
*/
this._elapsed = 0;
/**
* Transition elapsed timer.
*
* @name Phaser.Scenes.ScenePlugin#_target
* @type {?Phaser.Scenes.Scene}
* @private
* @since 3.5.0
*/
this._target = null;
/**
* Transition duration.
*
* @name Phaser.Scenes.ScenePlugin#_duration
* @type {number}
* @private
* @since 3.5.0
*/
this._duration = 0;
/**
* Transition callback.
*
* @name Phaser.Scenes.ScenePlugin#_onUpdate
* @type {function}
* @private
* @since 3.5.0
*/
this._onUpdate;
/**
* Transition callback scope.
*
* @name Phaser.Scenes.ScenePlugin#_onUpdateScope
* @type {object}
* @private
* @since 3.5.0
*/
this._onUpdateScope;
/**
* Will this Scene sleep (true) after the transition, or stop (false)
*
* @name Phaser.Scenes.ScenePlugin#_willSleep
* @type {boolean}
* @private
* @since 3.5.0
*/
this._willSleep = false;
/**
* Will this Scene be removed from the Scene Manager after the transition completes?
*
* @name Phaser.Scenes.ScenePlugin#_willRemove
* @type {boolean}
* @private
* @since 3.5.0
*/
this._willRemove = false;
scene.sys.events.once(Events.BOOT, this.boot, this);
scene.sys.events.on(Events.START, this.pluginStart, this);
},
/**
* This method is called automatically, only once, when the Scene is first created.
* Do not invoke it directly.
*
* @method Phaser.Scenes.ScenePlugin#boot
* @private
* @since 3.0.0
*/
boot: function ()
{
this.systems.events.once(Events.DESTROY, this.destroy, this);
},
/**
* This method is called automatically by the Scene when it is starting up.
* It is responsible for creating local systems, properties and listening for Scene events.
* Do not invoke it directly.
*
* @method Phaser.Scenes.ScenePlugin#pluginStart
* @private
* @since 3.5.0
*/
pluginStart: function ()
{
this._target = null;
this.systems.events.once(Events.SHUTDOWN, this.shutdown, this);
},
/**
* Shutdown this Scene and run the given one.
*
* This will happen at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#start
* @since 3.0.0
*
* @param {string} [key] - The Scene to start.
* @param {object} [data] - The Scene data.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
start: function (key, data)
{
if (key === undefined) { key = this.key; }
this.manager.queueOp('stop', this.key);
this.manager.queueOp('start', key, data);
return this;
},
/**
* Restarts this Scene.
*
* This will happen at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#restart
* @since 3.4.0
*
* @param {object} [data] - The Scene data.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
restart: function (data)
{
var key = this.key;
this.manager.queueOp('stop', key);
this.manager.queueOp('start', key, data);
return this;
},
/**
* This will start a transition from the current Scene to the target Scene given.
*
* The transition will last for the duration specified in milliseconds.
*
* You can have the target Scene moved above or below this one in the display list.
*
* You can specify an update callback. This callback will be invoked _every frame_ for the duration
* of the transition.
*
* This Scene can either be sent to sleep at the end of the transition, or stopped. The default is to stop.
*
* There are also 5 transition related events: This scene will emit the event `transitionout` when
* the transition begins, which is typically the frame after calling this method.
*
* The target Scene will emit the event `transitioninit` when that Scene's `init` method is called.
* It will then emit the event `transitionstart` when its `create` method is called.
* If the Scene was sleeping and has been woken up, it will emit the event `transitionwake` instead of these two,
* as the Scenes `init` and `create` methods are not invoked when a Scene wakes up.
*
* When the duration of the transition has elapsed it will emit the event `transitioncomplete`.
* These events are cleared of all listeners when the Scene shuts down, but not if it is sent to sleep.
*
* It's important to understand that the duration of the transition begins the moment you call this method.
* If the Scene you are transitioning to includes delayed processes, such as waiting for files to load, the
* time still counts down even while that is happening. If the game itself pauses, or something else causes
* this Scenes update loop to stop, then the transition will also pause for that duration. There are
* checks in place to prevent you accidentally stopping a transitioning Scene but if you've got code to
* override this understand that until the target Scene completes it might never be unlocked for input events.
*
* @method Phaser.Scenes.ScenePlugin#transition
* @fires Phaser.Scenes.Events#TRANSITION_OUT
* @since 3.5.0
*
* @param {Phaser.Types.Scenes.SceneTransitionConfig} config - The transition configuration object.
*
* @return {boolean} `true` is the transition was started, otherwise `false`.
*/
transition: function (config)
{
if (config === undefined) { config = {}; }
var key = GetFastValue(config, 'target', false);
var target = this.manager.getScene(key);
if (!key || !this.checkValidTransition(target))
{
return false;
}
var duration = GetFastValue(config, 'duration', 1000);
this._elapsed = 0;
this._target = target;
this._duration = duration;
this._willSleep = GetFastValue(config, 'sleep', false);
this._willRemove = GetFastValue(config, 'remove', false);
var callback = GetFastValue(config, 'onUpdate', null);
if (callback)
{
this._onUpdate = callback;
this._onUpdateScope = GetFastValue(config, 'onUpdateScope', this.scene);
}
var allowInput = GetFastValue(config, 'allowInput', false);
this.settings.transitionAllowInput = allowInput;
var targetSettings = target.sys.settings;
targetSettings.isTransition = true;
targetSettings.transitionFrom = this.scene;
targetSettings.transitionDuration = duration;
targetSettings.transitionAllowInput = allowInput;
if (GetFastValue(config, 'moveAbove', false))
{
this.manager.moveAbove(this.key, key);
}
else if (GetFastValue(config, 'moveBelow', false))
{
this.manager.moveBelow(this.key, key);
}
if (target.sys.isSleeping())
{
target.sys.wake(GetFastValue(config, 'data'));
}
else
{
this.manager.start(key, GetFastValue(config, 'data'));
}
this.systems.events.emit(Events.TRANSITION_OUT, target, duration);
this.systems.events.on(Events.UPDATE, this.step, this);
return true;
},
/**
* Checks to see if this Scene can transition to the target Scene or not.
*
* @method Phaser.Scenes.ScenePlugin#checkValidTransition
* @private
* @since 3.5.0
*
* @param {Phaser.Scene} target - The Scene to test against.
*
* @return {boolean} `true` if this Scene can transition, otherwise `false`.
*/
checkValidTransition: function (target)
{
// Not a valid target if it doesn't exist, isn't active or is already transitioning in or out
if (!target || target.sys.isActive() || target.sys.isTransitioning() || target === this.scene || this.systems.isTransitioning())
{
return false;
}
return true;
},
/**
* A single game step. This is only called if the parent Scene is transitioning
* out to another Scene.
*
* @method Phaser.Scenes.ScenePlugin#step
* @private
* @since 3.5.0
*
* @param {number} time - The current time. Either a High Resolution Timer value if it comes from Request Animation Frame, or Date.now if using SetTimeout.
* @param {number} delta - The delta time in ms since the last frame. This is a smoothed and capped value based on the FPS rate.
*/
step: function (time, delta)
{
this._elapsed += delta;
this.transitionProgress = Clamp(this._elapsed / this._duration, 0, 1);
if (this._onUpdate)
{
this._onUpdate.call(this._onUpdateScope, this.transitionProgress);
}
if (this._elapsed >= this._duration)
{
this.transitionComplete();
}
},
/**
* Called by `step` when the transition out of this scene to another is over.
*
* @method Phaser.Scenes.ScenePlugin#transitionComplete
* @private
* @fires Phaser.Scenes.Events#TRANSITION_COMPLETE
* @since 3.5.0
*/
transitionComplete: function ()
{
var targetSys = this._target.sys;
var targetSettings = this._target.sys.settings;
// Stop the step
this.systems.events.off(Events.UPDATE, this.step, this);
// Notify target scene
targetSys.events.emit(Events.TRANSITION_COMPLETE, this.scene);
// Clear target scene settings
targetSettings.isTransition = false;
targetSettings.transitionFrom = null;
// Clear local settings
this._duration = 0;
this._target = null;
this._onUpdate = null;
this._onUpdateScope = null;
// Now everything is clear we can handle what happens to this Scene
if (this._willRemove)
{
this.manager.remove(this.key);
}
else if (this._willSleep)
{
this.systems.sleep();
}
else
{
this.manager.stop(this.key);
}
},
/**
* Add the Scene into the Scene Manager and start it if 'autoStart' is true or the Scene config 'active' property is set.
*
* @method Phaser.Scenes.ScenePlugin#add
* @since 3.0.0
*
* @param {string} key - The Scene key.
* @param {(Phaser.Scene|Phaser.Types.Scenes.SettingsConfig|Phaser.Types.Scenes.CreateSceneFromObjectConfig|function)} sceneConfig - The config for the Scene.
* @param {boolean} autoStart - Whether to start the Scene after it's added.
* @param {object} [data] - Optional data object. This will be set as Scene.settings.data and passed to `Scene.init`.
*
* @return {Phaser.Scene} An instance of the Scene that was added to the Scene Manager.
*/
add: function (key, sceneConfig, autoStart, data)
{
return this.manager.add(key, sceneConfig, autoStart, data);
},
/**
* Launch the given Scene and run it in parallel with this one.
*
* This will happen at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#launch
* @since 3.0.0
*
* @param {string} key - The Scene to launch.
* @param {object} [data] - The Scene data.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
launch: function (key, data)
{
if (key && key !== this.key)
{
this.manager.queueOp('start', key, data);
}
return this;
},
/**
* Runs the given Scene, but does not change the state of this Scene.
*
* This will happen at the next Scene Manager update, not immediately.
*
* If the given Scene is paused, it will resume it. If sleeping, it will wake it.
* If not running at all, it will be started.
*
* Use this if you wish to open a modal Scene by calling `pause` on the current
* Scene, then `run` on the modal Scene.
*
* @method Phaser.Scenes.ScenePlugin#run
* @since 3.10.0
*
* @param {string} key - The Scene to run.
* @param {object} [data] - A data object that will be passed to the Scene and emitted in its ready, wake, or resume events.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
run: function (key, data)
{
if (key && key !== this.key)
{
this.manager.queueOp('run', key, data);
}
return this;
},
/**
* Pause the Scene - this stops the update step from happening but it still renders.
*
* This will happen at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#pause
* @since 3.0.0
*
* @param {string} [key] - The Scene to pause.
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted in its pause event.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
pause: function (key, data)
{
if (key === undefined) { key = this.key; }
this.manager.queueOp('pause', key, data);
return this;
},
/**
* Resume the Scene - starts the update loop again.
*
* This will happen at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#resume
* @since 3.0.0
*
* @param {string} [key] - The Scene to resume.
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted in its resume event.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
resume: function (key, data)
{
if (key === undefined) { key = this.key; }
this.manager.queueOp('resume', key, data);
return this;
},
/**
* Makes the Scene sleep (no update, no render) but doesn't shutdown.
*
* This will happen at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#sleep
* @since 3.0.0
*
* @param {string} [key] - The Scene to put to sleep.
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted in its sleep event.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
sleep: function (key, data)
{
if (key === undefined) { key = this.key; }
this.manager.queueOp('sleep', key, data);
return this;
},
/**
* Makes the Scene wake-up (starts update and render)
*
* This will happen at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#wake
* @since 3.0.0
*
* @param {string} [key] - The Scene to wake up.
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted in its wake event.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
wake: function (key, data)
{
if (key === undefined) { key = this.key; }
this.manager.queueOp('wake', key, data);
return this;
},
/**
* Makes this Scene sleep then starts the Scene given.
*
* This will happen at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#switch
* @since 3.0.0
*
* @param {string} key - The Scene to start.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
switch: function (key)
{
if (key !== this.key)
{
this.manager.queueOp('switch', this.key, key);
}
return this;
},
/**
* Shutdown the Scene, clearing display list, timers, etc.
*
* This happens at the next Scene Manager update, not immediately.
*
* @method Phaser.Scenes.ScenePlugin#stop
* @since 3.0.0
*
* @param {string} [key] - The Scene to stop.
* @param {any} [data] - Optional data object to pass to Scene.Systems.shutdown.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
stop: function (key, data)
{
if (key === undefined) { key = this.key; }
this.manager.queueOp('stop', key, data);
return this;
},
/**
* Sets the active state of the given Scene.
*
* @method Phaser.Scenes.ScenePlugin#setActive
* @since 3.0.0
*
* @param {boolean} value - If `true` the Scene will be resumed. If `false` it will be paused.
* @param {string} [key] - The Scene to set the active state of.
* @param {object} [data] - An optional data object that will be passed to the Scene and emitted with its events.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
setActive: function (value, key, data)
{
if (key === undefined) { key = this.key; }
var scene = this.manager.getScene(key);
if (scene)
{
scene.sys.setActive(value, data);
}
return this;
},
/**
* Sets the visible state of the given Scene.
*
* @method Phaser.Scenes.ScenePlugin#setVisible
* @since 3.0.0
*
* @param {boolean} value - The visible value.
* @param {string} [key] - The Scene to set the visible state for.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
setVisible: function (value, key)
{
if (key === undefined) { key = this.key; }
var scene = this.manager.getScene(key);
if (scene)
{
scene.sys.setVisible(value);
}
return this;
},
/**
* Checks if the given Scene is sleeping or not?
*
* @method Phaser.Scenes.ScenePlugin#isSleeping
* @since 3.0.0
*
* @param {string} [key] - The Scene to check.
*
* @return {boolean} Whether the Scene is sleeping.
*/
isSleeping: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isSleeping(key);
},
/**
* Checks if the given Scene is running or not?
*
* @method Phaser.Scenes.ScenePlugin#isActive
* @since 3.0.0
*
* @param {string} [key] - The Scene to check.
*
* @return {boolean} Whether the Scene is running.
*/
isActive: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isActive(key);
},
/**
* Checks if the given Scene is paused or not?
*
* @method Phaser.Scenes.ScenePlugin#isPaused
* @since 3.17.0
*
* @param {string} [key] - The Scene to check.
*
* @return {boolean} Whether the Scene is paused.
*/
isPaused: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isPaused(key);
},
/**
* Checks if the given Scene is visible or not?
*
* @method Phaser.Scenes.ScenePlugin#isVisible
* @since 3.0.0
*
* @param {string} [key] - The Scene to check.
*
* @return {boolean} Whether the Scene is visible.
*/
isVisible: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isVisible(key);
},
/**
* Swaps the position of two scenes in the Scenes list.
*
* This controls the order in which they are rendered and updated.
*
* @method Phaser.Scenes.ScenePlugin#swapPosition
* @since 3.2.0
*
* @param {string} keyA - The first Scene to swap.
* @param {string} [keyB] - The second Scene to swap. If none is given it defaults to this Scene.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
swapPosition: function (keyA, keyB)
{
if (keyB === undefined) { keyB = this.key; }
if (keyA !== keyB)
{
this.manager.swapPosition(keyA, keyB);
}
return this;
},
/**
* Swaps the position of two scenes in the Scenes list, so that Scene B is directly above Scene A.
*
* This controls the order in which they are rendered and updated.
*
* @method Phaser.Scenes.ScenePlugin#moveAbove
* @since 3.2.0
*
* @param {string} keyA - The Scene that Scene B will be moved to be above.
* @param {string} [keyB] - The Scene to be moved. If none is given it defaults to this Scene.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveAbove: function (keyA, keyB)
{
if (keyB === undefined) { keyB = this.key; }
if (keyA !== keyB)
{
this.manager.moveAbove(keyA, keyB);
}
return this;
},
/**
* Swaps the position of two scenes in the Scenes list, so that Scene B is directly below Scene A.
*
* This controls the order in which they are rendered and updated.
*
* @method Phaser.Scenes.ScenePlugin#moveBelow
* @since 3.2.0
*
* @param {string} keyA - The Scene that Scene B will be moved to be below.
* @param {string} [keyB] - The Scene to be moved. If none is given it defaults to this Scene.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveBelow: function (keyA, keyB)
{
if (keyB === undefined) { keyB = this.key; }
if (keyA !== keyB)
{
this.manager.moveBelow(keyA, keyB);
}
return this;
},
/**
* Removes a Scene from the SceneManager.
*
* The Scene is removed from the local scenes array, it's key is cleared from the keys
* cache and Scene.Systems.destroy is then called on it.
*
* If the SceneManager is processing the Scenes when this method is called it will
* queue the operation for the next update sequence.
*
* @method Phaser.Scenes.ScenePlugin#remove
* @since 3.2.0
*
* @param {(string|Phaser.Scene)} [key] - The Scene to be removed.
*
* @return {Phaser.Scenes.SceneManager} This SceneManager.
*/
remove: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.remove(key);
return this;
},
/**
* Moves a Scene up one position in the Scenes list.
*
* @method Phaser.Scenes.ScenePlugin#moveUp
* @since 3.0.0
*
* @param {string} [key] - The Scene to move.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveUp: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.moveUp(key);
return this;
},
/**
* Moves a Scene down one position in the Scenes list.
*
* @method Phaser.Scenes.ScenePlugin#moveDown
* @since 3.0.0
*
* @param {string} [key] - The Scene to move.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
moveDown: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.moveDown(key);
return this;
},
/**
* Brings a Scene to the top of the Scenes list.
*
* This means it will render above all other Scenes.
*
* @method Phaser.Scenes.ScenePlugin#bringToTop
* @since 3.0.0
*
* @param {string} [key] - The Scene to move.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
bringToTop: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.bringToTop(key);
return this;
},
/**
* Sends a Scene to the back of the Scenes list.
*
* This means it will render below all other Scenes.
*
* @method Phaser.Scenes.ScenePlugin#sendToBack
* @since 3.0.0
*
* @param {string} [key] - The Scene to move.
*
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
*/
sendToBack: function (key)
{
if (key === undefined) { key = this.key; }
this.manager.sendToBack(key);
return this;
},
/**
* Retrieve a Scene.
*
* @method Phaser.Scenes.ScenePlugin#get
* @since 3.0.0
*
* @param {string} key - The Scene to retrieve.
*
* @return {Phaser.Scene} The Scene.
*/
get: function (key)
{
return this.manager.getScene(key);
},
/**
* Retrieves the numeric index of a Scene in the Scenes list.
*
* @method Phaser.Scenes.ScenePlugin#getIndex
* @since 3.7.0
*
* @param {(string|Phaser.Scene)} [key] - The Scene to get the index of.
*
* @return {number} The index of the Scene.
*/
getIndex: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.getIndex(key);
},
/**
* The Scene that owns this plugin is shutting down.
* We need to kill and reset all internal properties as well as stop listening to Scene events.
*
* @method Phaser.Scenes.ScenePlugin#shutdown
* @private
* @since 3.0.0
*/
shutdown: function ()
{
var eventEmitter = this.systems.events;
eventEmitter.off(Events.SHUTDOWN, this.shutdown, this);
eventEmitter.off(Events.POST_UPDATE, this.step, this);
eventEmitter.off(Events.TRANSITION_OUT);
},
/**
* The Scene that owns this plugin is being destroyed.
* We need to shutdown and then kill off all external references.
*
* @method Phaser.Scenes.ScenePlugin#destroy
* @private
* @since 3.0.0
*/
destroy: function ()
{
this.shutdown();
this.scene.sys.events.off(Events.START, this.start, this);
this.scene = null;
this.systems = null;
this.settings = null;
this.manager = null;
}
});