0 votes

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:

func save_scene():
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)

Load scene:

func load_scene(scene_name):

 var next_scene = null

# Looking if scene has already been saved once in Temp Saves, otherwise loads the 
   original scene
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?

Godot version 3.5
in Engine by (17 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.