Quellcode durchsuchen

:sparkles: added a smoother transition

Felix Bytow vor 10 Monaten
Ursprung
Commit
3a0ae9cc24

+ 30 - 0
assets/scenes/transition.gd

@@ -0,0 +1,30 @@
+extends Control
+class_name Transition
+
+signal game_fully_hidden
+signal game_fully_visible
+
+@onready var label: Label = $Label
+@onready var animation_player: AnimationPlayer = $AnimationPlayer
+
+@export var text: String:
+	set(new_value):
+		label.text = new_value
+	get:
+		return label.text
+
+func slide_in():
+	animation_player.play("slide-in")
+	await animation_player.animation_finished
+	game_fully_hidden.emit()
+
+func slide_out():
+	animation_player.play("slide-out")
+	await animation_player.animation_finished
+	game_fully_visible.emit()
+
+func transition(display_text: String = ""):
+	text = display_text
+	slide_in()
+	await get_tree().create_timer(2).timeout
+	slide_out()

+ 73 - 0
assets/scenes/transition.tscn

@@ -0,0 +1,73 @@
+[gd_scene load_steps=8 format=3 uid="uid://ce8cu4romympf"]
+
+[ext_resource type="Texture2D" uid="uid://b6nsk6rd8a7sn" path="res://assets/textures/menu_background.jpg" id="1_cwnax"]
+[ext_resource type="Script" path="res://assets/scenes/transition.gd" id="1_jl8cy"]
+[ext_resource type="FontFile" uid="uid://cqtognhaksl7j" path="res://assets/fonts/Potra.ttf" id="3_liow6"]
+
+[sub_resource type="Animation" id="Animation_7tdps"]
+resource_name = "slide-out"
+step = 0.0333333
+tracks/0/type = "value"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath(".:position")
+tracks/0/interp = 2
+tracks/0/loop_wrap = false
+tracks/0/keys = {
+"times": PackedFloat32Array(0, 1),
+"transitions": PackedFloat32Array(1, 1),
+"update": 0,
+"values": [Vector2(0, 0), Vector2(-1280, 0)]
+}
+
+[sub_resource type="Animation" id="Animation_sqshj"]
+resource_name = "slide-in"
+step = 0.0333333
+tracks/0/type = "value"
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/path = NodePath(".:position")
+tracks/0/interp = 2
+tracks/0/loop_wrap = false
+tracks/0/keys = {
+"times": PackedFloat32Array(0, 1),
+"transitions": PackedFloat32Array(1, 1),
+"update": 0,
+"values": [Vector2(-1280, 0), Vector2(0, 0)]
+}
+
+[sub_resource type="AnimationLibrary" id="AnimationLibrary_3vpft"]
+_data = {
+"slide-in": SubResource("Animation_sqshj"),
+"slide-out": SubResource("Animation_7tdps")
+}
+
+[sub_resource type="LabelSettings" id="LabelSettings_sm7j6"]
+font = ExtResource("3_liow6")
+font_size = 69
+
+[node name="Transition" type="Control"]
+process_mode = 3
+layout_mode = 3
+anchors_preset = 0
+script = ExtResource("1_jl8cy")
+
+[node name="Background" type="TextureRect" parent="."]
+layout_mode = 1
+offset_right = 1280.0
+offset_bottom = 720.0
+texture = ExtResource("1_cwnax")
+
+[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
+libraries = {
+"": SubResource("AnimationLibrary_3vpft")
+}
+
+[node name="Label" type="Label" parent="."]
+layout_mode = 0
+offset_left = 215.0
+offset_top = 322.0
+offset_right = 646.0
+offset_bottom = 405.0
+label_settings = SubResource("LabelSettings_sm7j6")
+horizontal_alignment = 1

BIN
assets/textures/Light_Overlay.png


+ 34 - 0
assets/textures/Light_Overlay.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://r2ph4fobqo17"
+path="res://.godot/imported/Light_Overlay.png-c126c153354ab9ab26e1c0dded29affd.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://assets/textures/Light_Overlay.png"
+dest_files=["res://.godot/imported/Light_Overlay.png-c126c153354ab9ab26e1c0dded29affd.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1

BIN
assets/textures/game_background.jpg


+ 4 - 0
screens/game.gd

@@ -1,9 +1,13 @@
 extends Node2D
 
 @onready var health_bar = $HealthBar
+@onready var transition = $Overlay/Transition
 
 var direction = -1
 
+func _ready() -> void:
+	transition.slide_out()
+
 func _process(_delta: float) -> void:
 	if Input.is_action_pressed("ui_cancel"):
 		get_tree().change_scene_to_file("res://screens/main_menu.tscn")

+ 20 - 3
screens/game.tscn

@@ -1,8 +1,14 @@
-[gd_scene load_steps=4 format=3 uid="uid://c483fkssc36s"]
+[gd_scene load_steps=7 format=3 uid="uid://c483fkssc36s"]
 
 [ext_resource type="Script" path="res://screens/game.gd" id="1_4dd0q"]
 [ext_resource type="Texture2D" uid="uid://djifkreeh0nb4" path="res://assets/textures/game_background.jpg" id="2_qk61j"]
-[ext_resource type="PackedScene" uid="uid://bnoxyhq2ha6r1" path="res://assets/scenes/health_bar.tscn" id="2_x77og"]
+[ext_resource type="PackedScene" path="res://assets/scenes/health_bar.tscn" id="2_x77og"]
+[ext_resource type="Texture2D" uid="uid://r2ph4fobqo17" path="res://assets/textures/Light_Overlay.png" id="3_86s7d"]
+[ext_resource type="PackedScene" uid="uid://ce8cu4romympf" path="res://assets/scenes/transition.tscn" id="4_yc6k4"]
+
+[sub_resource type="CanvasItemMaterial" id="CanvasItemMaterial_yhw6y"]
+blend_mode = 1
+light_mode = 1
 
 [node name="Game" type="Node2D"]
 script = ExtResource("1_4dd0q")
@@ -13,10 +19,21 @@ position = Vector2(640, 360)
 scale = Vector2(0.5, 0.5)
 texture = ExtResource("2_qk61j")
 
+[node name="Light-Overlay" type="Sprite2D" parent="."]
+material = SubResource("CanvasItemMaterial_yhw6y")
+position = Vector2(640, 360)
+scale = Vector2(0.5, 0.5)
+texture = ExtResource("3_86s7d")
+
 [node name="HealthBar" parent="." instance=ExtResource("2_x77og")]
-position = Vector2(640, 63)
+position = Vector2(640, 58)
 
 [node name="Timer" type="Timer" parent="."]
 autostart = true
 
+[node name="Overlay" type="CanvasLayer" parent="."]
+layer = 10
+
+[node name="Transition" parent="Overlay" instance=ExtResource("4_yc6k4")]
+
 [connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]