Simplify transition code

Used the queue system in AnimationPlayer to queue animation
Removed an unnecessary animation
Renamed files
Renamed signal screen_covered to faded_to_black
Removed comments from LevelLoader
This commit is contained in:
Nathan Lovato 2020-05-02 18:29:48 -06:00
parent 91e0659b8c
commit 2742ee66e8
9 changed files with 115 additions and 105 deletions

View file

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Before After
Before After

View file

@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
path="res://.import/loading_icon.png-e328504ca04771078a22cab4caafd41a.stex"
path="res://.import/loading_wheel.png-07a52355d62247afcaaaf79302a3311d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/UI/loading_icon.png"
dest_files=[ "res://.import/loading_icon.png-e328504ca04771078a22cab4caafd41a.stex" ]
source_file="res://assets/UI/loading_wheel.png"
dest_files=[ "res://.import/loading_wheel.png-07a52355d62247afcaaaf79302a3311d.stex" ]
[params]

View file

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Before After
Before After

View file

@ -2,15 +2,15 @@
importer="texture"
type="StreamTexture"
path="res://.import/player_art.png-7b84e8940437deef8a50bb0d84c732ca.stex"
path="res://.import/robi_portrait.png-68ad9ce9f4cb884df10b44b5417451b8.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/UI/player_art.png"
dest_files=[ "res://.import/player_art.png-7b84e8940437deef8a50bb0d84c732ca.stex" ]
source_file="res://assets/UI/robi_portrait.png"
dest_files=[ "res://.import/robi_portrait.png-68ad9ce9f4cb884df10b44b5417451b8.stex" ]
[params]

View file

@ -8,8 +8,6 @@ var _level: Node2D = null
onready var scene_tree := get_tree()
func setup(game: Node, player: Player, Level: PackedScene) -> void:
_game = game
_player = player
@ -19,13 +17,11 @@ func setup(game: Node, player: Player, Level: PackedScene) -> void:
func trigger(NewLevel: PackedScene, portal_name: String = "") -> void:
if _level:
scene_tree.paused = true
_game.transition.start_transition_animation()
# Covers the screen before changing the level to avoid visual discrepancies
yield(_game.transition, "screen_covered")
_game.transition.fade_to_black()
yield(_game.transition, "faded_to_black")
_level.queue_free()
yield(_level, "tree_exited")
# The player is removed after the transition is covering the screen
_game.remove_child(_player)
_level = NewLevel.instance()
@ -45,7 +41,6 @@ func trigger(NewLevel: PackedScene, portal_name: String = "") -> void:
_game.add_child(_level)
_game.add_child(_player)
# The loading is done
_game.transition.finish_transition_animation()
_game.transition.fade_back_in()
scene_tree.paused = false

View file

@ -4,7 +4,7 @@
[ext_resource path="res://assets/theme/gdquest.theme" type="Theme" id=2]
[ext_resource path="res://src/UI/debug/DebugDock.gd" type="Script" id=3]
[ext_resource path="res://src/UI/debug/DebugPanel.tscn" type="PackedScene" id=4]
[ext_resource path="res://src/UI/Transition.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/UI/LoadingTransition.tscn" type="PackedScene" id=5]
[ext_resource path="res://src/Player/Player.tscn" type="PackedScene" id=8]
[ext_resource path="res://src/Levels/SkyParallaxBackground.tscn" type="PackedScene" id=9]

View file

@ -0,0 +1,21 @@
extends ColorRect
signal faded_to_black
onready var animation_player: AnimationPlayer = $AnimationPlayer
func fade_to_black() -> void:
animation_player.play("fade_in")
animation_player.queue("fade_in_extras")
animation_player.queue("loading")
func fade_back_in() -> void:
animation_player.clear_queue()
animation_player.play("fade_out")
func _on_AnimationPlayer_animation_changed(old_name: String, new_name: String) -> void:
if old_name == "fade_in":
emit_signal("faded_to_black")

View file

@ -1,13 +1,12 @@
[gd_scene load_steps=10 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://assets/UI/loading_icon.png" type="Texture" id=1]
[ext_resource path="res://assets/UI/player_art.png" type="Texture" id=2]
[ext_resource path="res://src/UI/Transition.gd" type="Script" id=3]
[ext_resource path="res://assets/UI/loading_wheel.png" type="Texture" id=1]
[ext_resource path="res://assets/UI/robi_portrait.png" type="Texture" id=2]
[ext_resource path="res://src/UI/LoadingTransition.gd" type="Script" id=3]
[sub_resource type="Animation" id=1]
resource_name = "<BASE>"
resource_name = "SETUP"
length = 0.001
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
@ -20,6 +19,18 @@ tracks/0/keys = {
"update": 0,
"values": [ Color( 1, 1, 1, 0 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath(".:visible")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ false ]
}
[sub_resource type="Animation" id=2]
resource_name = "fade_in"
@ -31,13 +42,13 @@ tracks/0/loop_wrap = false
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.5, 0.6 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"times": PoolRealArray( 0, 0.6 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 1 ) ]
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("LoadingSprite:modulate")
tracks/1/path = NodePath("SpinningWheel:modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
@ -49,7 +60,7 @@ tracks/1/keys = {
"values": [ Color( 1, 1, 1, 0 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("PlayerArtSprite:modulate")
tracks/2/path = NodePath("Robi:modulate")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
@ -60,12 +71,24 @@ tracks/2/keys = {
"update": 0,
"values": [ Color( 1, 1, 1, 0 ) ]
}
tracks/3/type = "value"
tracks/3/path = NodePath(".:visible")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ true ]
}
[sub_resource type="Animation" id=3]
resource_name = "fade_in_extras"
resource_name = "fade_in_loading"
length = 0.3
tracks/0/type = "value"
tracks/0/path = NodePath("LoadingSprite:frame")
tracks/0/path = NodePath("SpinningWheel:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
@ -77,7 +100,7 @@ tracks/0/keys = {
"values": [ 0 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("LoadingSprite:modulate")
tracks/1/path = NodePath("SpinningWheel:modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
@ -89,7 +112,7 @@ tracks/1/keys = {
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("PlayerArtSprite:modulate")
tracks/2/path = NodePath("Robi:modulate")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
@ -101,7 +124,7 @@ tracks/2/keys = {
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
}
tracks/3/type = "value"
tracks/3/path = NodePath("PlayerArtSprite:position")
tracks/3/path = NodePath("Robi:position")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
@ -113,7 +136,7 @@ tracks/3/keys = {
"values": [ Vector2( 350, 862 ) ]
}
tracks/4/type = "value"
tracks/4/path = NodePath("PlayerArtSprite:flip_h")
tracks/4/path = NodePath("Robi:flip_h")
tracks/4/interp = 1
tracks/4/loop_wrap = true
tracks/4/imported = false
@ -134,45 +157,53 @@ tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.6 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
}
[sub_resource type="Animation" id=5]
resource_name = "fade_out_extras"
length = 0.3
tracks/0/type = "value"
tracks/0/path = NodePath("LoadingSprite:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.3 ),
"times": PoolRealArray( 0.2, 0.6 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("PlayerArtSprite:modulate")
tracks/1/path = NodePath("SpinningWheel:modulate")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.3 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
"times": PoolRealArray( 0.3 ),
"transitions": PoolRealArray( 1 ),
"update": 3,
"values": [ Color( 1, 1, 1, 0 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("Robi:modulate")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0.3 ),
"transitions": PoolRealArray( 1 ),
"update": 3,
"values": [ Color( 1, 1, 1, 0 ) ]
}
tracks/3/type = "value"
tracks/3/path = NodePath(".:visible")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0.6 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ false ]
}
[sub_resource type="Animation" id=6]
length = 3.6
loop = true
tracks/0/type = "value"
tracks/0/path = NodePath("LoadingSprite:frame")
tracks/0/path = NodePath("SpinningWheel:frame")
tracks/0/interp = 0
tracks/0/loop_wrap = false
tracks/0/imported = false
@ -184,7 +215,7 @@ tracks/0/keys = {
"values": [ 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("PlayerArtSprite:position")
tracks/1/path = NodePath("Robi:position")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
@ -196,7 +227,7 @@ tracks/1/keys = {
"values": [ Vector2( 350, 862 ), Vector2( 450, 832 ), Vector2( 550, 862 ), Vector2( 650, 832 ), Vector2( 750, 862 ), Vector2( 850, 832 ), Vector2( 950, 862 ), Vector2( 1050, 832 ), Vector2( 1150, 862 ), Vector2( 1250, 832 ), Vector2( 1150, 862 ), Vector2( 1050, 832 ), Vector2( 950, 862 ), Vector2( 850, 832 ), Vector2( 750, 862 ), Vector2( 650, 832 ), Vector2( 550, 862 ), Vector2( 450, 832 ) ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("PlayerArtSprite:flip_h")
tracks/2/path = NodePath("Robi:flip_h")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
@ -208,11 +239,10 @@ tracks/2/keys = {
"values": [ false, true ]
}
[node name="Transition" type="ColorRect"]
[node name="LoadingTransition" type="ColorRect"]
pause_mode = 2
modulate = Color( 1, 1, 1, 0 )
margin_right = 1920.0
margin_bottom = 1080.0
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
color = Color( 0, 0, 0, 1 )
script = ExtResource( 3 )
@ -221,23 +251,23 @@ __meta__ = {
}
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
autoplay = "<BASE>"
anims/<BASE> = SubResource( 1 )
autoplay = "SETUP"
anims/SETUP = SubResource( 1 )
anims/fade_in = SubResource( 2 )
anims/fade_in_extras = SubResource( 3 )
anims/fade_in_loading = SubResource( 3 )
anims/fade_out = SubResource( 4 )
anims/fade_out_extras = SubResource( 5 )
anims/loading = SubResource( 6 )
[node name="LoadingSprite" type="Sprite" parent="."]
[node name="SpinningWheel" type="Sprite" parent="."]
modulate = Color( 1, 1, 1, 0 )
position = Vector2( 1809.7, 975.4 )
scale = Vector2( 2, 2 )
texture = ExtResource( 1 )
hframes = 8
frame = 6
[node name="PlayerArtSprite" type="Sprite" parent="."]
[node name="Robi" type="Sprite" parent="."]
modulate = Color( 1, 1, 1, 0 )
position = Vector2( 350, 862 )
position = Vector2( 850, 832 )
texture = ExtResource( 2 )
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_AnimationPlayer_animation_finished"]
[connection signal="animation_changed" from="AnimationPlayer" to="." method="_on_AnimationPlayer_animation_changed"]

View file

@ -1,36 +0,0 @@
extends ColorRect
signal screen_covered
var _loading_anim_started := false
onready var _animation_player: AnimationPlayer = $AnimationPlayer
# The level transition animations will be fade_outin->[fade_in_extras->
# loading->fade_out_extras->]fade_out
# [fade_in_extras->loading->fade_out_extras->] is optional and its
# length depends on the extra time the LevelLoader takes to load the next level
func start_transition_animation() -> void:
_animation_player.play("fade_in")
func finish_transition_animation() -> void:
if _loading_anim_started:
_animation_player.play("fade_out_extras")
_loading_anim_started = false
else:
_animation_player.play("fade_out")
func _on_AnimationPlayer_animation_finished(anim_name: String) -> void:
if anim_name == "fade_in":
emit_signal("screen_covered")
_animation_player.play("fade_in_extras")
elif anim_name == "fade_in_extras":
_loading_anim_started = true
_animation_player.play("loading")
elif anim_name == "fade_out_extras":
_animation_player.play("fade_out")