|
|
|
 |
Reply From: |
Constannnnnt |
For selection, you can basically create a menu and add buttons. Then, when a button is clicked, emit a signal to switch to the corresponding scene. Check the video for menu creation: https://www.youtube.com/watch?v=S9EUIfjfgEY
To load and change scenes, check the previous question: How to load and change scenes - Archive - Godot Forum
Scene Switching
What you’re looking for is in the Docs @ Using SceneTree — Godot Engine (latest) documentation in English
An example:
MainScene.tscn
┖╴Main
┠╴Camera
┖╴Title
┖╴(Title Stuff)
Main.gd Node Script:
extends Spatial
onready var current_scene = get_node("Title")
func goto_scene(path):
call_deferred("_deferred_scene", path)
func _deferred_scene(path):
# It is now safe to remove the current scene
current_scene.free()
# Load the new scene.
var new_scene = ResourceLoader.load(path)
# Instance the new scene.
current_scene = new_scene.instance()
# Add it to the active scene, as child of root.
get_tree().get_root().add_child(current_scene)
# Make it compatible with the SceneTree.change_scene() API.
get_tree().set_current_scene(current_scene)
func _input(event):
#Action keys set in Project > Project Settings > Input Map
if Input.is_action_just_pressed("keyOne"):
goto_scene("res://pathTo/SceneOne.tscn")
if Input.is_action_just_pressed("KeyTwo"):
goto_scene("res://pathTo/SceneTwo.tscn")
if Input.is_action_just_pressed("ui_accept"):
goto_scene("res://pathTo/Title.tscn")
if Input.is_action_just_pressed("ui_cancel"):
get_tree().quit()
Wakatta | 2020-07-23 07:42
To load and change scenes, check the previous question: How to load and change scenes - Archive - Godot Forum
Sorry, Not what I was Looking for. I went through a few of those but wasn’t what I needed.
However, after posting this, I rummaged through some different types of tutorials and pieced together this:
extends Spatial
func _ready():
pass
func _physics_process(_delta):
if Input.is_action_pressed("ui_one"):
get_tree().change_scene("res://scenes/scene1.tscn")
if Input.is_action_pressed("ui_two"):
get_tree().change_scene("res://scenes/scene2.tscn")
if Input.is_action_pressed("ui_three"):
get_tree().change_scene("res://scenes/scene3.tscn")
if Input.is_action_pressed("ui_four"):
get_tree().change_scene("res://scenes/scene4.tscn")
if Input.is_action_pressed("ui_home"):
get_tree().change_scene("res://start.tscn")
func _unhandled_input(event):
if event.is_action_pressed("ui_quit"):
get_tree().quit()
This works great, however I get caution’s that says “The function ‘change_scene()’ returns a value, but this value is never used.”
It doesn’t seem to interfere however, I don’t know what this means or what to change to get rid of the errors. Any Ideas how to make this better?
Wekita | 2020-07-23 23:43
As far as the Documentation goes, I don’t know enough about programming to understand it. I wish I did. Unless it’s all written out for me to study, I can’t interpret it.
(My brains wired weird like that.)
Some stuff I can understand in the doc’s, but other stuff I can’t.
Wekita | 2020-07-23 23:58
It is a warning, not an error. Check the doc: SceneTree — Godot Engine (stable) documentation in English.
You don’t have to worry about it and just leave it there. If you do, you can try
var e = get_tree().change_scene("res://start.tscn")
if (e):
print("change scene successfully")
else:
print("failed changing scene")
Constannnnnt | 2020-07-27 22:29
Yeah i know what you mean.
In school i never understood tectonic plates no matter who or how it was taught. That being said if you don’t understand something skip it and try again at a later date when your knowledge is up to par.
Wakatta | 2021-04-12 21:11