/
SceneManager.js
1755 lines (1511 loc) · 45.2 KB
/
SceneManager.js
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 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../utils/Class');
var CONST = require('./const');
var Events = require('./events');
var GameEvents = require('../core/events');
var GetValue = require('../utils/object/GetValue');
var LoaderEvents = require('../loader/events');
var NOOP = require('../utils/NOOP');
var Scene = require('./Scene');
var Systems = require('./Systems');
/**
* @classdesc
* The Scene Manager.
*
* The Scene Manager is a Game level system, responsible for creating, processing and updating all of the
* Scenes in a Game instance.
*
* You should not usually interact directly with the Scene Manager at all. Instead, you should use
* the Scene Plugin, which is available from every Scene in your game via the `this.scene` property.
*
* Using methods in this Scene Manager directly will break queued operations and can cause runtime
* errors. Instead, go via the Scene Plugin. Every feature this Scene Manager provides is also
* available via the Scene Plugin.
*
* @class SceneManager
* @memberof Phaser.Scenes
* @constructor
* @since 3.0.0
*
* @param {Phaser.Game} game - The Phaser.Game instance this Scene Manager belongs to.
* @param {object} sceneConfig - Scene specific configuration settings.
*/
var SceneManager = new Class({
initialize:
function SceneManager (game, sceneConfig)
{
/**
* The Game that this SceneManager belongs to.
*
* @name Phaser.Scenes.SceneManager#game
* @type {Phaser.Game}
* @since 3.0.0
*/
this.game = game;
/**
* An object that maps the keys to the scene so we can quickly get a scene from a key without iteration.
*
* @name Phaser.Scenes.SceneManager#keys
* @type {Record<string, Phaser.Scene>}
* @since 3.0.0
*/
this.keys = {};
/**
* The array in which all of the scenes are kept.
*
* @name Phaser.Scenes.SceneManager#scenes
* @type {Phaser.Scene[]}
* @since 3.0.0
*/
this.scenes = [];
/**
* Scenes pending to be added are stored in here until the manager has time to add it.
*
* @name Phaser.Scenes.SceneManager#_pending
* @type {array}
* @private
* @since 3.0.0
*/
this._pending = [];
/**
* An array of scenes waiting to be started once the game has booted.
*
* @name Phaser.Scenes.SceneManager#_start
* @type {array}
* @private
* @since 3.0.0
*/
this._start = [];
/**
* An operations queue, because we don't manipulate the scenes array during processing.
*
* @name Phaser.Scenes.SceneManager#_queue
* @type {array}
* @private
* @since 3.0.0
*/
this._queue = [];
/**
* Boot time data to merge.
*
* @name Phaser.Scenes.SceneManager#_data
* @type {object}
* @private
* @since 3.4.0
*/
this._data = {};
/**
* Is the Scene Manager actively processing the Scenes list?
*
* @name Phaser.Scenes.SceneManager#isProcessing
* @type {boolean}
* @default false
* @readonly
* @since 3.0.0
*/
this.isProcessing = false;
/**
* Has the Scene Manager properly started?
*
* @name Phaser.Scenes.SceneManager#isBooted
* @type {boolean}
* @default false
* @readonly
* @since 3.4.0
*/
this.isBooted = false;
/**
* Do any of the Cameras in any of the Scenes require a custom viewport?
* If not we can skip scissor tests.
*
* @name Phaser.Scenes.SceneManager#customViewports
* @type {number}
* @default 0
* @since 3.12.0
*/
this.customViewports = 0;
/**
* This system Scene is created during `bootQueue` and is a default
* empty Scene that lives outside of the Scene list, but can be used
* by plugins and managers that need access to a live Scene, without
* being tied to one.
*
* @name Phaser.Scenes.SceneManager#systemScene
* @type {Phaser.Scene}
* @since 3.60.0
*/
this.systemScene;
if (sceneConfig)
{
if (!Array.isArray(sceneConfig))
{
sceneConfig = [ sceneConfig ];
}
for (var i = 0; i < sceneConfig.length; i++)
{
// The i === 0 part just autostarts the first Scene given (unless it says otherwise in its config)
this._pending.push({
key: 'default',
scene: sceneConfig[i],
autoStart: (i === 0),
data: {}
});
}
}
game.events.once(GameEvents.READY, this.bootQueue, this);
},
/**
* Internal first-time Scene boot handler.
*
* @method Phaser.Scenes.SceneManager#bootQueue
* @private
* @since 3.2.0
*/
bootQueue: function ()
{
if (this.isBooted)
{
return;
}
// Create the system Scene
this.systemScene = this.createSceneFromInstance('__SYSTEM', new Scene());
var i;
var entry;
var key;
var sceneConfig;
for (i = 0; i < this._pending.length; i++)
{
entry = this._pending[i];
key = entry.key;
sceneConfig = entry.scene;
var newScene;
if (sceneConfig instanceof Scene)
{
newScene = this.createSceneFromInstance(key, sceneConfig);
}
else if (typeof sceneConfig === 'object')
{
newScene = this.createSceneFromObject(key, sceneConfig);
}
else if (typeof sceneConfig === 'function')
{
newScene = this.createSceneFromFunction(key, sceneConfig);
}
// Replace key in case the scene changed it
key = newScene.sys.settings.key;
this.keys[key] = newScene;
this.scenes.push(newScene);
// Any data to inject?
if (this._data[key])
{
newScene.sys.settings.data = this._data[key].data;
if (this._data[key].autoStart)
{
entry.autoStart = true;
}
}
if (entry.autoStart || newScene.sys.settings.active)
{
this._start.push(key);
}
}
// Clear the pending lists
this._pending.length = 0;
this._data = {};
this.isBooted = true;
// _start might have been populated by the above
for (i = 0; i < this._start.length; i++)
{
entry = this._start[i];
this.start(entry);
}
this._start.length = 0;
},
/**
* Process the Scene operations queue.
*
* @method Phaser.Scenes.SceneManager#processQueue
* @since 3.0.0
*/
processQueue: function ()
{
var pendingLength = this._pending.length;
var queueLength = this._queue.length;
if (pendingLength === 0 && queueLength === 0)
{
return;
}
var i;
var entry;
if (pendingLength)
{
for (i = 0; i < pendingLength; i++)
{
entry = this._pending[i];
this.add(entry.key, entry.scene, entry.autoStart, entry.data);
}
// _start might have been populated by this.add
for (i = 0; i < this._start.length; i++)
{
entry = this._start[i];
this.start(entry);
}
// Clear the pending lists
this._start.length = 0;
this._pending.length = 0;
}
for (i = 0; i < this._queue.length; i++)
{
entry = this._queue[i];
this[entry.op](entry.keyA, entry.keyB);
}
this._queue.length = 0;
},
/**
* Adds a new Scene into the SceneManager.
* You must give each Scene a unique key by which you'll identify it.
*
* The `sceneConfig` can be:
*
* * A `Phaser.Scene` object, or an object that extends it.
* * A plain JavaScript object
* * A JavaScript ES6 Class that extends `Phaser.Scene`
* * A JavaScript ES5 prototype based Class
* * A JavaScript function
*
* If a function is given then a new Scene will be created by calling it.
*
* @method Phaser.Scenes.SceneManager#add
* @since 3.0.0
*
* @param {string} key - A unique key used to reference the Scene, i.e. `MainMenu` or `Level1`.
* @param {(Phaser.Types.Scenes.SceneType)} sceneConfig - The config for the Scene
* @param {boolean} [autoStart=false] - If `true` the Scene will be started immediately after being added.
* @param {object} [data] - Optional data object. This will be set as `Scene.settings.data` and passed to `Scene.init`, and `Scene.create`.
*
* @return {?Phaser.Scene} The added Scene, if it was added immediately, otherwise `null`.
*/
add: function (key, sceneConfig, autoStart, data)
{
if (autoStart === undefined) { autoStart = false; }
if (data === undefined) { data = {}; }
// If processing or not booted then put scene into a holding pattern
if (this.isProcessing || !this.isBooted)
{
this._pending.push({
key: key,
scene: sceneConfig,
autoStart: autoStart,
data: data
});
if (!this.isBooted)
{
this._data[key] = { data: data };
}
return null;
}
key = this.getKey(key, sceneConfig);
var newScene;
if (sceneConfig instanceof Scene)
{
newScene = this.createSceneFromInstance(key, sceneConfig);
}
else if (typeof sceneConfig === 'object')
{
sceneConfig.key = key;
newScene = this.createSceneFromObject(key, sceneConfig);
}
else if (typeof sceneConfig === 'function')
{
newScene = this.createSceneFromFunction(key, sceneConfig);
}
// Any data to inject?
newScene.sys.settings.data = data;
// Replace key in case the scene changed it
key = newScene.sys.settings.key;
this.keys[key] = newScene;
this.scenes.push(newScene);
if (autoStart || newScene.sys.settings.active)
{
if (this._pending.length)
{
this._start.push(key);
}
else
{
this.start(key);
}
}
return newScene;
},
/**
* 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.SceneManager#remove
* @since 3.2.0
*
* @param {string} key - A unique key used to reference the Scene, i.e. `MainMenu` or `Level1`.
*
* @return {this} This Scene Manager instance.
*/
remove: function (key)
{
if (this.isProcessing)
{
this._queue.push({ op: 'remove', keyA: key, keyB: null });
}
else
{
var sceneToRemove = this.getScene(key);
if (!sceneToRemove || sceneToRemove.sys.isTransitioning())
{
return this;
}
var index = this.scenes.indexOf(sceneToRemove);
var sceneKey = sceneToRemove.sys.settings.key;
if (index > -1)
{
delete this.keys[sceneKey];
this.scenes.splice(index, 1);
if (this._start.indexOf(sceneKey) > -1)
{
index = this._start.indexOf(sceneKey);
this._start.splice(index, 1);
}
sceneToRemove.sys.destroy();
}
}
return this;
},
/**
* Boot the given Scene.
*
* @method Phaser.Scenes.SceneManager#bootScene
* @private
* @fires Phaser.Scenes.Events#TRANSITION_INIT
* @since 3.0.0
*
* @param {Phaser.Scene} scene - The Scene to boot.
*/
bootScene: function (scene)
{
var sys = scene.sys;
var settings = sys.settings;
sys.sceneUpdate = NOOP;
if (scene.init)
{
scene.init.call(scene, settings.data);
settings.status = CONST.INIT;
if (settings.isTransition)
{
sys.events.emit(Events.TRANSITION_INIT, settings.transitionFrom, settings.transitionDuration);
}
}
var loader;
if (sys.load)
{
loader = sys.load;
loader.reset();
}
if (loader && scene.preload)
{
scene.preload.call(scene);
settings.status = CONST.LOADING;
// Start the loader going as we have something in the queue
loader.once(LoaderEvents.COMPLETE, this.loadComplete, this);
loader.start();
}
else
{
// No preload? Then there was nothing to load either
this.create(scene);
}
},
/**
* Handles load completion for a Scene's Loader.
*
* Starts the Scene that the Loader belongs to.
*
* @method Phaser.Scenes.SceneManager#loadComplete
* @private
* @since 3.0.0
*
* @param {Phaser.Loader.LoaderPlugin} loader - The loader that has completed loading.
*/
loadComplete: function (loader)
{
// TODO - Remove. This should *not* be handled here
// Try to unlock HTML5 sounds every time any loader completes
if (this.game.sound && this.game.sound.onBlurPausedSounds)
{
this.game.sound.unlock();
}
this.create(loader.scene);
},
/**
* Handle payload completion for a Scene.
*
* @method Phaser.Scenes.SceneManager#payloadComplete
* @private
* @since 3.0.0
*
* @param {Phaser.Loader.LoaderPlugin} loader - The loader that has completed loading its Scene's payload.
*/
payloadComplete: function (loader)
{
this.bootScene(loader.scene);
},
/**
* Updates the Scenes.
*
* @method Phaser.Scenes.SceneManager#update
* @since 3.0.0
*
* @param {number} time - Time elapsed.
* @param {number} delta - Delta time from the last update.
*/
update: function (time, delta)
{
this.processQueue();
this.isProcessing = true;
// Loop through the active scenes in reverse order
for (var i = this.scenes.length - 1; i >= 0; i--)
{
var sys = this.scenes[i].sys;
if (sys.settings.status > CONST.START && sys.settings.status <= CONST.RUNNING)
{
sys.step(time, delta);
}
if (sys.scenePlugin._target)
{
sys.scenePlugin.step(time, delta);
}
}
},
/**
* Renders the Scenes.
*
* @method Phaser.Scenes.SceneManager#render
* @since 3.0.0
*
* @param {(Phaser.Renderer.Canvas.CanvasRenderer|Phaser.Renderer.WebGL.WebGLRenderer)} renderer - The renderer to use.
*/
render: function (renderer)
{
// Loop through the scenes in forward order
for (var i = 0; i < this.scenes.length; i++)
{
var sys = this.scenes[i].sys;
if (sys.settings.visible && sys.settings.status >= CONST.LOADING && sys.settings.status < CONST.SLEEPING)
{
sys.render(renderer);
}
}
this.isProcessing = false;
},
/**
* Calls the given Scene's {@link Phaser.Scene#create} method and updates its status.
*
* @method Phaser.Scenes.SceneManager#create
* @private
* @fires Phaser.Scenes.Events#CREATE
* @fires Phaser.Scenes.Events#TRANSITION_INIT
* @since 3.0.0
*
* @param {Phaser.Scene} scene - The Scene to create.
*/
create: function (scene)
{
var sys = scene.sys;
var settings = sys.settings;
if (scene.create)
{
settings.status = CONST.CREATING;
scene.create.call(scene, settings.data);
if (settings.status === CONST.DESTROYED)
{
return;
}
}
if (settings.isTransition)
{
sys.events.emit(Events.TRANSITION_START, settings.transitionFrom, settings.transitionDuration);
}
// If the Scene has an update function we'll set it now, otherwise it'll remain as NOOP
if (scene.update)
{
sys.sceneUpdate = scene.update;
}
settings.status = CONST.RUNNING;
sys.events.emit(Events.CREATE, scene);
},
/**
* Creates and initializes a Scene from a function.
*
* @method Phaser.Scenes.SceneManager#createSceneFromFunction
* @private
* @since 3.0.0
*
* @param {string} key - The key of the Scene.
* @param {function} scene - The function to create the Scene from.
*
* @return {Phaser.Scene} The created Scene.
*/
createSceneFromFunction: function (key, scene)
{
var newScene = new scene();
if (newScene instanceof Scene)
{
var configKey = newScene.sys.settings.key;
if (configKey !== '')
{
key = configKey;
}
if (this.keys.hasOwnProperty(key))
{
throw new Error('Cannot add a Scene with duplicate key: ' + key);
}
return this.createSceneFromInstance(key, newScene);
}
else
{
newScene.sys = new Systems(newScene);
newScene.sys.settings.key = key;
newScene.sys.init(this.game);
return newScene;
}
},
/**
* Creates and initializes a Scene instance.
*
* @method Phaser.Scenes.SceneManager#createSceneFromInstance
* @private
* @since 3.0.0
*
* @param {string} key - The key of the Scene.
* @param {Phaser.Scene} newScene - The Scene instance.
*
* @return {Phaser.Scene} The created Scene.
*/
createSceneFromInstance: function (key, newScene)
{
var configKey = newScene.sys.settings.key;
if (configKey === '')
{
newScene.sys.settings.key = key;
}
newScene.sys.init(this.game);
return newScene;
},
/**
* Creates and initializes a Scene from an Object definition.
*
* @method Phaser.Scenes.SceneManager#createSceneFromObject
* @private
* @since 3.0.0
*
* @param {string} key - The key of the Scene.
* @param {(string|Phaser.Types.Scenes.SettingsConfig|Phaser.Types.Scenes.CreateSceneFromObjectConfig)} sceneConfig - The Scene config.
*
* @return {Phaser.Scene} The created Scene.
*/
createSceneFromObject: function (key, sceneConfig)
{
var newScene = new Scene(sceneConfig);
var configKey = newScene.sys.settings.key;
if (configKey !== '')
{
key = configKey;
}
else
{
newScene.sys.settings.key = key;
}
newScene.sys.init(this.game);
// Extract callbacks
var defaults = [ 'init', 'preload', 'create', 'update', 'render' ];
for (var i = 0; i < defaults.length; i++)
{
var sceneCallback = GetValue(sceneConfig, defaults[i], null);
if (sceneCallback)
{
newScene[defaults[i]] = sceneCallback;
}
}
// Now let's move across any other functions or properties that may exist in the extend object:
/*
scene: {
preload: preload,
create: create,
extend: {
hello: 1,
test: 'atari',
addImage: addImage
}
}
*/
if (sceneConfig.hasOwnProperty('extend'))
{
for (var propertyKey in sceneConfig.extend)
{
if (!sceneConfig.extend.hasOwnProperty(propertyKey))
{
continue;
}
var value = sceneConfig.extend[propertyKey];
if (propertyKey === 'data' && newScene.hasOwnProperty('data') && typeof value === 'object')
{
// Populate the DataManager
newScene.data.merge(value);
}
else if (propertyKey !== 'sys')
{
newScene[propertyKey] = value;
}
}
}
return newScene;
},
/**
* Retrieves the key of a Scene from a Scene config.
*
* @method Phaser.Scenes.SceneManager#getKey
* @private
* @since 3.0.0
*
* @param {string} key - The key to check in the Scene config.
* @param {(Phaser.Scene|Phaser.Types.Scenes.SettingsConfig|function)} sceneConfig - The Scene config.
*
* @return {string} The Scene key.
*/
getKey: function (key, sceneConfig)
{
if (!key) { key = 'default'; }
if (typeof sceneConfig === 'function')
{
return key;
}
else if (sceneConfig instanceof Scene)
{
key = sceneConfig.sys.settings.key;
}
else if (typeof sceneConfig === 'object' && sceneConfig.hasOwnProperty('key'))
{
key = sceneConfig.key;
}
// By this point it's either 'default' or extracted from the Scene
if (this.keys.hasOwnProperty(key))
{
throw new Error('Cannot add a Scene with duplicate key: ' + key);
}
else
{
return key;
}
},
/**
* Returns an array of all the current Scenes being managed by this Scene Manager.
*
* You can filter the output by the active state of the Scene and choose to have
* the array returned in normal or reversed order.
*
* @method Phaser.Scenes.SceneManager#getScenes
* @since 3.16.0
*
* @generic {Phaser.Scene[]} T - [$return]
*
* @param {boolean} [isActive=true] - Only include Scene's that are currently active?
* @param {boolean} [inReverse=false] - Return the array of Scenes in reverse?
*
* @return {Phaser.Scene[]} An array containing all of the Scenes in the Scene Manager.
*/
getScenes: function (isActive, inReverse)
{
if (isActive === undefined) { isActive = true; }
if (inReverse === undefined) { inReverse = false; }
var out = [];
var scenes = this.scenes;
for (var i = 0; i < scenes.length; i++)
{
var scene = scenes[i];
if (scene && (!isActive || (isActive && scene.sys.isActive())))
{
out.push(scene);
}
}
return (inReverse) ? out.reverse() : out;
},
/**
* Retrieves a Scene based on the given key.
*
* If an actual Scene is passed to this method, it can be used to check if
* its currently within the Scene Manager, or not.
*
* @method Phaser.Scenes.SceneManager#getScene
* @since 3.0.0
*
* @generic {Phaser.Scene} T
* @genericUse {(T|string)} - [key]
* @genericUse {T} - [$return]
*
* @param {(string|Phaser.Scene)} key - The key of the Scene to retrieve.
*
* @return {?Phaser.Scene} The Scene, or `null` if no matching Scene was found.
*/
getScene: function (key)
{
if (typeof key === 'string')
{
if (this.keys[key])
{
return this.keys[key];
}
}
else
{
for (var i = 0; i < this.scenes.length; i++)
{
if (key === this.scenes[i])
{
return key;
}
}
}
return null;
},
/**
* Determines whether a Scene is running.
*
* @method Phaser.Scenes.SceneManager#isActive
* @since 3.0.0
*
* @generic {Phaser.Scene} T
* @genericUse {(T|string)} - [key]
*
* @param {(string|Phaser.Scene)} key - The Scene to check.
*
* @return {boolean} Whether the Scene is running, or `null` if no matching Scene was found.
*/
isActive: function (key)
{
var scene = this.getScene(key);
if (scene)
{
return scene.sys.isActive();
}
return null;
},
/**
* Determines whether a Scene is paused.
*
* @method Phaser.Scenes.SceneManager#isPaused
* @since 3.17.0
*
* @generic {Phaser.Scene} T
* @genericUse {(T|string)} - [key]
*
* @param {(string|Phaser.Scene)} key - The Scene to check.
*
* @return {boolean} Whether the Scene is paused, or `null` if no matching Scene was found.
*/
isPaused: function (key)
{
var scene = this.getScene(key);
if (scene)
{
return scene.sys.isPaused();
}
return null;
},
/**
* Determines whether a Scene is visible.
*
* @method Phaser.Scenes.SceneManager#isVisible
* @since 3.0.0
*
* @generic {Phaser.Scene} T
* @genericUse {(T|string)} - [key]
*
* @param {(string|Phaser.Scene)} key - The Scene to check.
*
* @return {boolean} Whether the Scene is visible, or `null` if no matching Scene was found.
*/
isVisible: function (key)
{
var scene = this.getScene(key);
if (scene)
{
return scene.sys.isVisible();
}
return null;
},
/**
* Determines whether a Scene is sleeping.
*