global.gd 585 B

1234567891011121314151617181920212223
  1. extends Node
  2. var current_scene = null
  3. func goto_scene(scene):
  4. #load new scene
  5. var s = ResourceLoader.load(scene)
  6. #queue erasing old (don't use free because that scene is calling this method)
  7. current_scene.queue_free()
  8. #instance the new scene
  9. current_scene = s.instance()
  10. #add it to the active scene, as child of root
  11. get_scene().get_root().add_child(current_scene)
  12. func _ready():
  13. # get the current scene
  14. # it is always the last child of root,
  15. # after the autoloaded nodes
  16. var root = get_scene().get_root()
  17. current_scene = root.get_child( root.get_child_count() -1 )