I'm a beginner hoping to get advice on the best practice to manage multiple levels in a platform game. I've been looking through examples and searching but the answer isn't clear to me.
My top level node (I would call it root but it appears to be a child of get_tree().get_root()) is a Node2D called Main. My thinking is that I should have this Main node and then make the level a child of it, which seems common in the examples.
It seems like change_scene() is the intended way to change levels but if I call get_tree().change_scene(...) it replaces my top-level Main node with the new scene instead of replacing the level node with the new scene. I'm using Main like a singleton to keep high level management code so when change_scene replaces Main breaks the whole thing.
I managed to get it working as below but now I'm no longer using change_scene so it seems like I might be doing things abnormally.
Main.gd
extends Node2D
var level = null
func change_level(level_number):
if (level): remove_child(level)
var scene_filename = "res://src/Levels/Level%s.tscn" % level_number
level = load(scene_filename).instance()
add_child(level)
Is what I'm doing here considered good practice? Or should I be using change_scene to change levels? And if I use change_scene to change levels, how do I keep my Main node from getting replaced by the new scene?
Thanks!