generated from krampus/template-godot4
The dreaded screenshaker!
This commit is contained in:
parent
77b5048d04
commit
aa87f57f1f
|
@ -5,6 +5,8 @@ class_name Game extends Node
|
|||
|
||||
var _loading_resources := {}
|
||||
|
||||
@onready var viewport: GameViewportContainer = %ViewportContainer
|
||||
|
||||
@onready var content: Node = %Content
|
||||
@onready var loader_transition: AnimationPlayer = %LoaderTransition
|
||||
@onready var loading_screen: Control = %LoadingScreen
|
||||
|
|
|
@ -1,7 +1,35 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://cefit4bc8akbb"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://cefit4bc8akbb"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/game/game.gd" id="1_4qa87"]
|
||||
[ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="2_y3adf"]
|
||||
[ext_resource type="Script" path="res://src/ui/game_viewport_container.gd" id="3_rmm5i"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_c3dlb"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:visible")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [true]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath(".:modulate")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_2c1ud"]
|
||||
resource_name = "fade_in"
|
||||
|
@ -31,33 +59,6 @@ tracks/1/keys = {
|
|||
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_c3dlb"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath(".:visible")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [true]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath(".:modulate")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 1)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_xbqy2"]
|
||||
resource_name = "fade_out"
|
||||
length = 0.4
|
||||
|
@ -94,9 +95,11 @@ _data = {
|
|||
}
|
||||
|
||||
[node name="Game" type="Node" groups=["GameGroup"]]
|
||||
process_mode = 3
|
||||
script = ExtResource("1_4qa87")
|
||||
|
||||
[node name="Control" type="Control" parent="."]
|
||||
[node name="RootControl" type="Control" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
|
@ -104,7 +107,7 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="LoadingScreen" type="Control" parent="Control"]
|
||||
[node name="LoadingScreen" type="Control" parent="RootControl"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 128
|
||||
layout_mode = 1
|
||||
|
@ -115,7 +118,7 @@ grow_horizontal = 2
|
|||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="Control/LoadingScreen"]
|
||||
[node name="ColorRect" type="ColorRect" parent="RootControl/LoadingScreen"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
|
@ -125,7 +128,7 @@ grow_vertical = 2
|
|||
mouse_filter = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="Control/LoadingScreen"]
|
||||
[node name="MarginContainer" type="MarginContainer" parent="RootControl/LoadingScreen"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
|
@ -139,7 +142,7 @@ grow_vertical = 0
|
|||
theme_override_constants/margin_right = 64
|
||||
theme_override_constants/margin_bottom = 32
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="Control/LoadingScreen/MarginContainer"]
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="RootControl/LoadingScreen/MarginContainer"]
|
||||
custom_minimum_size = Vector2(160, 0)
|
||||
layout_mode = 2
|
||||
mouse_filter = 2
|
||||
|
@ -150,13 +153,15 @@ bbcode_enabled = true
|
|||
text = "[wave]LOADING...[/wave]"
|
||||
fit_content = true
|
||||
|
||||
[node name="LoaderTransition" type="AnimationPlayer" parent="Control/LoadingScreen"]
|
||||
[node name="LoaderTransition" type="AnimationPlayer" parent="RootControl/LoadingScreen"]
|
||||
unique_name_in_owner = true
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_1s0w0")
|
||||
}
|
||||
|
||||
[node name="ViewportContainer" type="SubViewportContainer" parent="Control"]
|
||||
[node name="ViewportContainer" type="SubViewportContainer" parent="RootControl"]
|
||||
unique_name_in_owner = true
|
||||
process_mode = 3
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
|
@ -164,8 +169,9 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
stretch = true
|
||||
script = ExtResource("3_rmm5i")
|
||||
|
||||
[node name="Viewport" type="SubViewport" parent="Control/ViewportContainer"]
|
||||
[node name="Viewport" type="SubViewport" parent="RootControl/ViewportContainer"]
|
||||
handle_input_locally = false
|
||||
msaa_2d = 3
|
||||
msaa_3d = 3
|
||||
|
@ -174,5 +180,6 @@ use_taa = true
|
|||
size = Vector2i(1280, 720)
|
||||
render_target_update_mode = 4
|
||||
|
||||
[node name="Content" type="Node" parent="Control/ViewportContainer/Viewport"]
|
||||
[node name="Content" type="Node" parent="RootControl/ViewportContainer/Viewport"]
|
||||
unique_name_in_owner = true
|
||||
process_mode = 1
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
class_name GameViewportContainer extends SubViewportContainer
|
||||
## SubViewportContainer with game-specific special effects
|
||||
|
||||
var _screen_shake_intensity: float = 0.0
|
||||
|
||||
@onready var root_control: Control = %RootControl
|
||||
|
||||
|
||||
## Start playing a screen shake effect.
|
||||
func screen_shake(intensity: float, duration: float = 0.2) -> void:
|
||||
var tween := get_tree().create_tween()
|
||||
_screen_shake_intensity = intensity
|
||||
tween.tween_property(self, "_screen_shake_intensity", 0.0, duration).set_trans(
|
||||
Tween.TRANS_CUBIC
|
||||
)
|
||||
tween.tween_callback(_reset_position)
|
||||
|
||||
|
||||
func _reset_position() -> void:
|
||||
position = Vector2.ZERO
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if _screen_shake_intensity > 0:
|
||||
position.x = randfn(0, _screen_shake_intensity)
|
||||
position.y = randfn(0, _screen_shake_intensity)
|
Loading…
Reference in New Issue