-
Notifications
You must be signed in to change notification settings - Fork 18
Features
When SceneManager is installed, you will gain access to the SceneManager
singleton. You can then trigger it's methods directly like so:
SceneManager.change_scene('res://demo/test.tscn')
There are similar methods for reloading your scene and making a fade without transition, read the API docs!
Now you can add your very own AnimationPlayer
to complement the one packaged in SceneManager!
First off, setup a new Scene
that has an AnimationPlayer
as its root node. Make and name all the animations you want, and make sure you have a RESET
animation that keeps all your visuals out of the screen.
Then, set your player in SceneManager via code (We recommend doing this as early as possible in your game. For example in the _ready()
method of an autoload or your first scene):
SceneManager.set_animation_player('res://demo/animation_player.tscn')
Now, whenever you call SceneManager.change_scene()
or any other transition function, you will be able to add new animation_name
, animation_name_enter
and/or animation_name_leave
options with the name of your animation.
You can even match an enter/leave pattern from SceneManager
! Just remember that animation_name
takes precedence, so you'll want to use the opposite enter/leave suffix on animation_name
.
SceneManager.change_scene('res://demo/test2.tscn', {"animation_name_enter": "roll", "pattern_leave": "squares"})
As always, check the demo in this repo or the API docs for more info!
Since GDScript now supports Callables, we can easily send functions as parameters in our transition options. This allows a pretty useful pattern to be easily implemented: Callbacks.
If you want some snippet of code to run at specific moments of a transition, you can send it inside of a callable like so:
SceneManager.change_scene("res://demo/test2.tscn", {
"on_tree_enter": func(scene): print("wow I just entered the tree!")
})
This is somewhat similar to how you could use Signals before, but the main advantage is that you can execute code declared in nodes that are already unmounted.
There are 4 currently available callbacks:
- "on_tree_enter": called when the new scene enters the tree
- "on_ready": called when the new scene is ready
- "on_fade_out": called when the fade_out is complete (screen is completely black)
- "on_fade_in": called when the fade_in is complete (transition is completely finished)
An easy way to keep track of important Nodes that only exist once in your scenes (like your player or your level tilemap), regardless of the name they have.
First off, you just have to set the flag and name in the editor:
Then just use it in your code like so:
SceneManager.get_entity("ColorRect").color = Color("#FFFFFF")
Of note, is that if you try and use this feature in a _ready()
function you will get an error. To circumvent this, wait for the scene to be loaded like so:
func _ready():
yield(SceneManager, "scene_loaded")
SceneManager.get_entity("ColorRect").color = Color("#FFFFFF")
Be sure to read the API docs for a more detailed explanation.