scene manager system
This commit is contained in:
parent
aa6b9cb4aa
commit
cc177f7beb
6 changed files with 74 additions and 3 deletions
Binary file not shown.
Binary file not shown.
30
autoloads/scene_manager.gd
Normal file
30
autoloads/scene_manager.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends Node
|
||||
|
||||
|
||||
@export var scene_parent: Node
|
||||
|
||||
|
||||
var current_scene: Node
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
var tree = get_tree()
|
||||
# capture main scene
|
||||
if tree.current_scene != self:
|
||||
change_scene(tree.current_scene)
|
||||
tree.current_scene = self
|
||||
|
||||
|
||||
func change_scene(new_scene: Node) -> void:
|
||||
# avoid infinite recursion :P
|
||||
if current_scene == new_scene:
|
||||
return
|
||||
# remove current scene
|
||||
if current_scene:
|
||||
scene_parent.remove_child(current_scene)
|
||||
current_scene.queue_free()
|
||||
# add new scene
|
||||
if new_scene.is_inside_tree():
|
||||
new_scene.get_parent().remove_child.call_deferred(new_scene)
|
||||
scene_parent.add_child.call_deferred(new_scene)
|
||||
current_scene = new_scene
|
37
autoloads/scene_manager.tscn
Normal file
37
autoloads/scene_manager.tscn
Normal file
|
@ -0,0 +1,37 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://dxrvocxjk8vs3"]
|
||||
|
||||
[ext_resource type="Script" path="res://autoloads/scene_manager.gd" id="1_d112a"]
|
||||
|
||||
[node name="SceneManager" type="Node" node_paths=PackedStringArray("scene_parent")]
|
||||
script = ExtResource("1_d112a")
|
||||
scene_parent = NodePath("HBoxContainer/MainView/SubViewportContainer/SubViewport")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="SideBar" type="Control" parent="HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="MainView" type="Control" parent="HBoxContainer"]
|
||||
custom_minimum_size = Vector2(288, 216)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 10
|
||||
|
||||
[node name="SubViewportContainer" type="SubViewportContainer" parent="HBoxContainer/MainView"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="HBoxContainer/MainView/SubViewportContainer"]
|
||||
handle_input_locally = false
|
||||
audio_listener_enable_3d = true
|
||||
size = Vector2i(288, 216)
|
||||
render_target_update_mode = 4
|
|
@ -213,9 +213,9 @@ delay_in_seconds = "0.0"
|
|||
[connection signal="charge_canceled" from="." to="Sounds/ChargeCancel" method="play"]
|
||||
[connection signal="shot" from="." to="Sounds/Shoot" method="play"]
|
||||
[connection signal="state_physics_processing" from="StateChart/Root/Idle" to="." method="_apply_gravity"]
|
||||
[connection signal="state_physics_processing" from="StateChart/Root/Moving" to="." method="_apply_gravity"]
|
||||
[connection signal="state_physics_processing" from="StateChart/Root/Moving" to="." method="_bounce_on_walls"]
|
||||
[connection signal="state_physics_processing" from="StateChart/Root/Moving" to="." method="_slow_to_stop"]
|
||||
[connection signal="state_physics_processing" from="StateChart/Root/Moving" to="." method="_apply_gravity"]
|
||||
[connection signal="state_entered" from="StateChart/Root/Charging" to="." method="_start_charge"]
|
||||
[connection signal="state_entered" from="StateChart/Root/Charging" to="Sounds/ChargeStart" method="play"]
|
||||
[connection signal="state_exited" from="StateChart/Root/Charging" to="." method="_end_charge"]
|
||||
|
|
|
@ -15,10 +15,14 @@ run/main_scene="res://test_scene.tscn"
|
|||
config/features=PackedStringArray("4.3", "GL Compatibility")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
SceneManager="*res://autoloads/scene_manager.tscn"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=320
|
||||
window/size/viewport_height=240
|
||||
window/size/viewport_width=384
|
||||
window/size/viewport_height=216
|
||||
window/stretch/mode="viewport"
|
||||
|
||||
[editor_plugins]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue