Advertisement
Guest User

Untitled

a guest
Jul 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.73 KB | None | 0 0
  1. while not save_game.eof_reached():
  2.         var current_line = parse_json(save_game.get_line())
  3.         # First we need to create the object and add it to the tree and set its position.
  4.         var new_object = load(current_line["filename"]).instance()
  5.         get_node(current_line["parent"]).add_child(new_object)
  6.         new_object.position = Vector2(current_line["pos_x"], current_line["pos_y"]))
  7.  
  8. // This keeps us going until there is nothing left to read in the file
  9. while not save_game.eof_reached():
  10.    
  11.     // We use .get_line() to get the next line in the save_game file object
  12.     // Using parse_json, we can store it as a dictionary in the "current_line" variable
  13.     // Current line in this case is equal to {"filename": "name.tscn", "parent": "name_of_parent_node", "pos_x": X0, "pos_y": X0}
  14.     var current_line = parse_json(save_game.get_line())
  15.    
  16.     // Current line here points to a filename we've saved in the folder elsewhere
  17.     // We access the filename value like we would with any other dictionary, through its key
  18.     // We use load to load the scene into memory
  19.     // then we create an instance of it
  20.     var new_object = load(current_line["filename"].instance()
  21.    
  22.     // We access the name of the node's parent
  23.     // Which is then passed to get_node to get that node's parent (This was added from an earlier line)
  24.     // Then, as "new_object" we add it to the parent node
  25.     get_node(current_line["parent"].add_child(new_object)
  26.  
  27.     // We get the node's position by accessing its "pos_x" and "pos_y" values
  28.     // 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
  29.     new_object.postion = Vector2(current_line["pos_x"], current_line["pos_y"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement