Persistent UI objects/components on scenes

This is another newbie question, but how do you create a persistent UI elements that will remain on your screen even if different scenes load ? Example would be a settings / sound icons, or a menu.

Hello @SlavomirDurej,
With phaser-3 now you can start multiple scenes.

here is an example about this which is on https://labs.phaser.io/index.html

2 Likes

Thank you, still would be nice if there was just a bit more info about this?
From lookling at the source code I I guessed the way to make it run is by calling this in the constructor?

Phaser.Scene.call(this, { key: ā€˜backgroundā€™, active: true }); Whereas ā€œkeyā€ referes to the scenes classes array? But those are class names, the ā€œkeyā€ variables are defined in constructor normaly, but then sometimes you just call superconstructor e.g. super({key: ā€œGameSceneā€}); right?

So when you want to use multiple scenes you use Phaser.Scene.call instead?

And then how do you communicate with those other scenes? What about their position on the z / depth axis ?

Where can I find any documentation / guides about this and similar concepts?

Hello again @SlavomirDurej,
For documentation, you can check: https://photonstorm.github.io/phaser3-docs/
And please see all examples on https://labs.phaser.io/index.html?dir=scenes/&q=

as for multiple scenes when you want, you can use this.scene.launch see this example.

for passing data from another scene see this example which is also on labs

I believe is the best way check online for your questions. :slight_smile:
After all if you really canā€™t find anything about your problem(which quite unlikely) then please do let us know about your problem and show us your code :slight_smile:

I believe there are really tons of questions about UIScene, similar to your question.

And for me, Iā€™m always looking the source code of phaser before i wrote something here :slight_smile:

Update:
Oh bdw just saw this 2 example too:

https://labs.phaser.io/view.html?src=src/scenes/ui%20scene%20es6.js

https://labs.phaser.io/view.html?src=src/scenes/ui%20scene.js -> this one specially called ā€œui scene.jsā€ on examples

1 Like

Thank you so much for your help!
Itā€™s not that I didnā€™t try to look for it, itā€™s just that itā€™s really difficult to look for a specific answers , when you donā€™t know where to look! Those API docs, are really only helpful, if you already know the general area or a specific area or classes you need to look up. For example this issue would be hidden somewhere in the constructor of the class extending Phaser.Scene by calling superconstructor with super({key: ā€œMenuā€, active:true}); (Iā€™m using typescript).
And so it happens this information is burried under: Namespaces > Phaser.Scenes.Settings
(not inside https://photonstorm.github.io/phaser3-docs/Phaser.Scene.html or Scene manager,) etcā€¦
which isnā€™t exactly intuitive?

and even there it says:

active boolean false Does the Scene start as active or not? An active Scene updates each step.

which still doesnā€™t mention that it allows these two scenes be visible or coexisting in paralel at the same timeā€¦ So for anybody thatā€™s working with Phaser only 2-3 days, this is pretty well hidden Iā€™d say.

Another problem is I know some other game libraries / platforms that have quite a different approach, which makes it a bit harder to use Phaser (such as Unity, OpenFL or Starling).

1 Like

I see your problem @SlavomirDurej, and really i was also sooo confused when i start working with phaser-3 at first place. But as much as you have write and search for these kinda stuff you learn more as you can imagine.

For this i actually never checked if itā€™s actually starting or not and also about updates idk :slight_smile: but we can always ask help from @rich or @samme i believe they and many others can help! :smiley:
As far as i understand, scenes are creating by SceneManager but doesnā€™t start therefor doesnā€™t have an update on the time.

1 Like

In the scene config active determines whether the scene will be started by the SceneManager after the scene is added by the manager. And once the scene is started its sys.settings.active flag is true. Specifically, the active flag is true for the scene states START and RUNNING and false for the others.

But read #119 and #121 for a guide to the scenes, thatā€™s a better place to start.

3 Likes

Thank you so much @samme this was mega useful! those dev logs should be featured much more prominently in the help section, or better yet, such articles could be compiled to a separate wiki page, and have their own sectionā€¦ itā€™s really useful and interesting information.

1 Like