so im currently making a RPG-Type game and i need to switch scenes between the main world and f.e. a house.
So i have a "Main.tscn" scene and a "House.tscn" scene and im using a SceneHandler-Scene to swtich between those two. So basically, when the player enteres a door in Main, its emitting a signal to the Scene handler to save the Main scene with ResourceSaver in a temporary folder and load the House.tscn scene. It then removes the Main node from itself and adds the House node as a child.
When i leave the House its doing basically the same thing, save the House.tscn in the Temporary folder, load Main.tscn from that temporary folder and remove the House node while adding the Main node to itself.
Save/Load scene functions:
var packed_scene = PackedScene.new()
# If scene already in Temp Saves, deletes old scene
if dir.file_exists("res://src/Temp Saves/" + current_scene.name + ".tscn"):
dir.remove("res://src/Temp Saves/" + current_scene.name + ".tscn")
ResourceSaver.save("res://src/Temp Saves/" + current_scene.name + ".tscn", packed_scene)
var next_scene = null
# Looking if scene has already been saved once in Temp Saves, otherwise loads the
if dir.file_exists("res://src/Temp Saves/" + scene_name + ".tscn"):
next_scene = load("res://src/Temp Saves/" + scene_name + ".tscn").instance()
elif dir.file_exists("res://src/Levels/" + scene_name + ".tscn"):
next_scene = load("res://src/Levels/" + scene_name + ".tscn").instance()
print("Scene '" + scene_name + "' not found!")
next_scene.connect("switch_scene", self, "_save_and_load_scene")
current_scene = next_scene
print("Current Scene: ", current_scene)
My problem is, when i load back into the temporary saved Main.tscn scene, the ParallaxBackgound is back on x=0, although the player is elevated up. When i jump down, the ParallaxBackgound and its layers are just going down into the ground asewell.
I opened the temprary Main.tscn scene and found that every ParallaxLayer position is set to a value, so i tried manually setting it to 0 in the _ready() function with:
for i in range(parallax_background.get_child_count()):
var layer: ParallaxLayer = parallax_background.get_child(i)
layer.position = Vector2(0, 0)
but that (for some reason) does not work.
The ParallaxBackgounds Offset is also set to a X and Y value, but setting these to Zero via code doesnt work either, while entering x=0 and y=0 in the editor does work.
Does anyone know how i can reset the ParallaxBackground?