Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while not save_game.eof_reached():
- var current_line = parse_json(save_game.get_line())
- # First we need to create the object and add it to the tree and set its position.
- var new_object = load(current_line["filename"]).instance()
- get_node(current_line["parent"]).add_child(new_object)
- new_object.position = Vector2(current_line["pos_x"], current_line["pos_y"]))
- // This keeps us going until there is nothing left to read in the file
- while not save_game.eof_reached():
- // We use .get_line() to get the next line in the save_game file object
- // Using parse_json, we can store it as a dictionary in the "current_line" variable
- // Current line in this case is equal to {"filename": "name.tscn", "parent": "name_of_parent_node", "pos_x": X0, "pos_y": X0}
- var current_line = parse_json(save_game.get_line())
- // Current line here points to a filename we've saved in the folder elsewhere
- // We access the filename value like we would with any other dictionary, through its key
- // We use load to load the scene into memory
- // then we create an instance of it
- var new_object = load(current_line["filename"].instance()
- // We access the name of the node's parent
- // Which is then passed to get_node to get that node's parent (This was added from an earlier line)
- // Then, as "new_object" we add it to the parent node
- get_node(current_line["parent"].add_child(new_object)
- // We get the node's position by accessing its "pos_x" and "pos_y" values
- // Then add those values to the node's position which is a Vector2() // Vector2's are just Array/Lists that are limited to 2 numbers really
- new_object.postion = Vector2(current_line["pos_x"], current_line["pos_y"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement