func on_gui_input(event):
if event is InputEventMouseButton and event.pressed:
pass
if event is InputEventKey and event.scancode == KEY_SPACE:
pass
Load scene at runtime
# if the path is wrong or the scene can't be loaded
# the `preload` function will fail at compile time
var bingo_scene = preload("res://Scenes/Bingo.tscn")
var bingo = null
func _ready():
bingo = bingo_scene.instance()
bingo.position = Vector2(1021, 790)
bingo.name = 'Bingo'
add_child(bingo)
But in case that scene is optional, then use a ResourceLoader
var bingo_scene_path = "res://Scenes/Bingo.tscn"
var bingo_scene = null
var bingo = null
func _enter_tree():
if ResourceLoader.exists(bingo_scene_path):
bingo_scene = ResourceLoader.load(bingo_scene_path)
func _ready():
if bingo_scene:
bingo = bingo_scene.instance()
bingo.name = 'Bingo'
bingo.position = Vector2(1021, 790)
add_child(bingo)
Reassign resources in code
Load textures as resources. Drag and drop resources into the editor for the path
onready var training_texture: Texture = load("res://Assets/meter_training.png")
Get local scene root
func get_local_scene_root(p_node : Node) -> Node:
while(p_node and not p_node.filename):
p_node = p_node.get_parent()
return p_node as Node