Skip to content

Commit 43fd10b

Browse files
committed
ScenePlugin.run is a new method that will run the given Scene and not change the state of the current Scene at all. If the scene is asleep, it will be woken. If it's paused, it will be resumed. If not running at all, it will be started.
1 parent a6e26ba commit 43fd10b

3 files changed

Lines changed: 75 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ TODO - Out of Canvas events
8787
* Camera has a new property `visible`. An invisible Camera will skip rendering and input tests of everything it can see. This allows you to create say a mini-cam and then toggle it on and off without needing to re-create it each time.
8888
* Camera has a new method `setVisible` which toggles its visible property.
8989
* `CameraManager.fromJSON` will now set the visible property is defined in the config.
90+
* `ScenePlugin.run` is a new method that will run the given Scene and not change the state of the current Scene at all. If the scene is asleep, it will be woken. If it's paused, it will be resumed. If not running at all, it will be started.
9091

9192
### Updates
9293

src/scene/SceneManager.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,49 @@ var SceneManager = new Class({
10111011
return this;
10121012
},
10131013

1014+
/**
1015+
* Runs the given Scene, but does not change the state of this Scene.
1016+
*
1017+
* If the given Scene is paused, it will resume it. If sleeping, it will wake it.
1018+
* If not running at all, it will be started.
1019+
*
1020+
* Use this if you wish to open a modal Scene by calling `pause` on the current
1021+
* Scene, then `run` on the modal Scene.
1022+
*
1023+
* @method Phaser.Scenes.SceneManager#run
1024+
* @since 3.10.0
1025+
*
1026+
* @param {string} key - The Scene to run.
1027+
* @param {object} [data] - A data object that will be passed to the Scene that is run _only if the Scene isn't asleep or paused_.
1028+
*
1029+
* @return {Phaser.Scenes.SceneManager} This Scene Manager.
1030+
*/
1031+
run: function (key, data)
1032+
{
1033+
var scene = this.getScene(key);
1034+
1035+
if (!scene)
1036+
{
1037+
return this;
1038+
}
1039+
1040+
if (scene.sys.isSleeping())
1041+
{
1042+
// Sleeping?
1043+
scene.sys.wake();
1044+
}
1045+
else if (scene.sys.isBooted && !scene.sys.isActive())
1046+
{
1047+
// Paused?
1048+
scene.sys.resume();
1049+
}
1050+
else
1051+
{
1052+
// Not actually running?
1053+
this.start(key, data);
1054+
}
1055+
},
1056+
10141057
/**
10151058
* Starts the given Scene.
10161059
*

src/scene/ScenePlugin.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,37 @@ var ScenePlugin = new Class({
498498
return this;
499499
},
500500

501+
/**
502+
* Runs the given Scene, but does not change the state of this Scene.
503+
*
504+
* If the given Scene is paused, it will resume it. If sleeping, it will wake it.
505+
* If not running at all, it will be started.
506+
*
507+
* Use this if you wish to open a modal Scene by calling `pause` on the current
508+
* Scene, then `run` on the modal Scene.
509+
*
510+
* @method Phaser.Scenes.ScenePlugin#run
511+
* @since 3.10.0
512+
*
513+
* @param {string} key - The Scene to run.
514+
* @param {object} [data] - A data object that will be passed to the Scene that is run _only if the Scene isn't asleep or paused_.
515+
*
516+
* @return {Phaser.Scenes.ScenePlugin} This ScenePlugin object.
517+
*/
518+
run: function (key, data)
519+
{
520+
if (this.settings.status !== CONST.RUNNING)
521+
{
522+
this.manager.queueOp('run', key, data);
523+
}
524+
else
525+
{
526+
this.manager.run(key, data);
527+
}
528+
529+
return this;
530+
},
531+
501532
/**
502533
* Pause the Scene - this stops the update step from happening but it still renders.
503534
*

0 commit comments

Comments
 (0)