Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | yedi | |
Old Version | Published before Godot 3 was released. |
Hi All.
- I have a project with 5 scenes.
- I use singleton logic to change screens
http://docs.godotengine.org/en/latest/tutorials/step_by_step/singletons_autoload.html - I have menu bar scene, as a child, on each screen
- The menu bar has button “Mode” with Toggle mode selected (in editor)
- If I select button on one screen (button is visible selected)
and then go to next screen the button return to the default status.
Question
Is the any way keep button pressed when I go from one screen to another, by using standard button setting ? or I have to come up with custom logic to keep button pressed all the time?
A quick and easy way would be the one you said.
Your ui should be used only for presentation, your logic and data should be separate from there visual appearance.
So you need to make a variable in a Singleton script and set/unset the variable according to the button press.
An example for this is sound toggle button which should retain it’s state.
You can make the sound button as a packed scene with a script in which it checks the global variable is status and sets it’s presentation inside the _ready()
This way it is as simple as instancing the scene and it will work everywhere.
A nice addition: Make a mute/unmute method in the Singleton and emit a signal when the variable changes. You can listen for that signal on any script. So you can make different sound toggle designs and all will be synced.
vinod | 2016-09-20 04:09
It looks like you want to preserve your GUI across scenes. If you use change_scene
, I would suggest you use sub-scene change instead. Take a look at option 3) from my answer here: Scene switching and returning? - Archive - Godot Forum
Note you don’t necessarily need a singleton.
Other options can be interesting too, as you are dealing with scene changing, I guess.
Zylann | 2016-09-20 11:47
Guys, appreciate you answers
Thank you
yedi | 2016-09-21 03:17