Posted June 27, 2017 by Ludonauta
#redesign
The way scenes work in Godot Engine is ingenious, basically, everything can be a scene. An object can be a scene, a sprite, a physical body, GUI, screens... So when you want to change from one scene to another you need to ask the main loop, the Scene Tree, to change the root scene (the one that triggers all the events that should be processed in the game). By using:
get_tree().change_scene(String scene_path)
we can change between levels on the game, screens and even between menus (e.g. from the main menu to the options).
By using signals , which are basically a visual application for the observer pattern, we can tell an object to send a message to another, the listener. We can then attach this message to a method in the listener which will then execute this method triggered by the message it received.
The game itself doesn't have a complex screen flow it is as it follows:
But this was enough to a lazy designer to think on a scalable solution for that.
So I designed a simple class which extends the built-in scene changing functionalities by allowing signals to pass scene paths as arguments when they trigger.
By doing this when designing and implementing the scene flow I just have to emit a signal to the root node, which inherits an abstract screen class, with the new scene's path. That's how it works:
That's my report for this week, hope you enjoyed <3