Add loading when load warcraft scene

This commit is contained in:
VAILLANT Jeremy
2021-05-09 17:10:40 +02:00
parent 275c0a080f
commit 78b566f5b8
4 changed files with 31 additions and 17 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
extends Control extends Control
# Load scene warcraft
func _on_WarCraft_pressed(): func _on_WarCraft_pressed():
get_tree().change_scene("res://scenes/levels/WarCraft.tscn") Global.goto_scene("res://scenes/levels/WarCraft.tscn")
+11 -4
View File
@@ -6,13 +6,20 @@
[node name="ChooseScene" type="Control"] [node name="ChooseScene" type="Control"]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
margin_left = 200.0
script = ExtResource( 1 ) script = ExtResource( 1 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="GridContainer" type="GridContainer" parent="."] [node name="games" type="Control" parent="."]
margin_left = 200.0
margin_right = 1024.0
margin_bottom = 600.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="GridContainer" type="GridContainer" parent="games"]
margin_left = 25.0 margin_left = 25.0
margin_top = 26.2599 margin_top = 26.2599
margin_right = 824.0 margin_right = 824.0
@@ -21,10 +28,10 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
[node name="WarCraft" type="TextureButton" parent="GridContainer"] [node name="WarCraft" type="TextureButton" parent="games/GridContainer"]
margin_right = 150.0 margin_right = 150.0
margin_bottom = 150.0 margin_bottom = 150.0
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
texture_normal = ExtResource( 2 ) texture_normal = ExtResource( 2 )
[connection signal="pressed" from="GridContainer/WarCraft" to="." method="_on_WarCraft_pressed"] [connection signal="pressed" from="games/GridContainer/WarCraft" to="." method="_on_WarCraft_pressed"]
+10 -4
View File
@@ -1,9 +1,15 @@
extends Spatial extends Spatial
export (PackedScene) var main = load("res://scenes/main.tscn") func _process(_delta):
# Event key "escape" and "godot event" ui_end
if Input.is_action_just_pressed("ui_end"):
_quit_to_menu()
func _notification(what): func _notification(what):
# Back to main scene # Notification for android back action
if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST: if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
var scene = main.instance() _quit_to_menu()
call_deferred("add_child", scene)
# Back to main scene
func _quit_to_menu():
Global.goto_scene("res://scenes/main.tscn")
+8 -8
View File
@@ -3,7 +3,7 @@ extends Node
export (PackedScene) var about = load("res://scenes/UI/About.tscn") export (PackedScene) var about = load("res://scenes/UI/About.tscn")
export (PackedScene) var scenes = load("res://scenes/UI/ChooseScene.tscn") export (PackedScene) var scenes = load("res://scenes/UI/ChooseScene.tscn")
var scene var current_scene = null
# Quit the game # Quit the game
func _on_Quit_pressed(): func _on_Quit_pressed():
@@ -12,17 +12,17 @@ func _on_Quit_pressed():
# Load scene about # Load scene about
func _on_About_pressed(): func _on_About_pressed():
_prepare_change_scene() _prepare_change_scene()
scene = about.instance() current_scene = about.instance()
add_child(scene) add_child(current_scene)
# Load scene for select game # Load scene for select game
func _on_New_pressed(): func _on_New_pressed():
_prepare_change_scene() _prepare_change_scene()
scene = scenes.instance() current_scene = scenes.instance()
add_child(scene) add_child(current_scene)
## PRIVATE ## PRIVATE
func _prepare_change_scene(): func _prepare_change_scene():
if (scene != null): if (current_scene != null):
remove_child(scene) remove_child(current_scene)
scene.call_deferred("free") current_scene.call_deferred("free")