test-client-godot/scenes/global.gd

48 lines
1.8 KiB
GDScript3
Raw Normal View History

2018-08-06 15:43:56 +00:00
extends Node
var current_scene = null
var character = null
var character_camera = null
var character_creation_mesh = null
2018-08-06 15:43:56 +00:00
var character_creation_camera = null
var player_name
var player_color
2018-08-06 15:43:56 +00:00
func _ready():
var root = get_tree().get_root()
# current_scene = root.get_child(root.get_child_count() -1)
current_scene = root.get_node( "Main/login_scene" )
# character = get_tree().get_root().get_node( "Main/Game/Character" )
# character_camera = get_tree().get_root().get_node( "Main/Game/Character/Camera_rotation_helper/Camera" )
# character_creation_camera = get_tree().get_root().get_node( "Main/login_scene/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/camera" )
2018-08-06 15:43:56 +00:00
func goto_scene(path, parent):
2018-08-06 15:43:56 +00:00
# This function will usually be called from a signal callback,
# or some other function from the running scene.
# Deleting the current scene at this point might be
# a bad idea, because it may be inside of a callback or function of it.
# The worst case will be a crash or unexpected behavior.
# The way around this is deferring the load to a later time, when
# it is ensured that no code from the current scene is running:
call_deferred("_deferred_goto_scene", path, parent)
2018-08-06 15:43:56 +00:00
func _deferred_goto_scene(path, parent):
2018-08-06 15:43:56 +00:00
# Immediately free the current scene,
# there is no risk here.
current_scene.free()
# Load new scene.
var s = ResourceLoader.load( path )
2018-08-06 15:43:56 +00:00
# Instance the new scene.
current_scene = s.instance()
# Add it to the active scene, as child of root.
get_tree().get_root().get_node( parent ).add_child( current_scene )
2018-08-06 15:43:56 +00:00
# Optional, to make it compatible with the SceneTree.change_scene() API.
get_tree().set_current_scene( current_scene )