game: add fps overlay
This commit is contained in:
@@ -12,6 +12,7 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
@onready var head = $Head
|
||||
@onready var camera = $Head/PlayerCamera
|
||||
@onready var player_debug = $Head/PlayerCamera/PlayerDebug
|
||||
@onready var overylay_fps = $Head/PlayerCamera/OverlayFPS
|
||||
@onready var player_stats = $PlayerStats
|
||||
@onready var anim_player = $AnimationPlayer
|
||||
@onready var muzzle_flash = $Head/PlayerCamera/pistol/MuzzleFlash
|
||||
@@ -39,6 +40,8 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
if Input.is_action_just_pressed("debug_overlay"):
|
||||
player_debug.visible = !player_debug.visible
|
||||
|
||||
if Input.is_action_just_pressed("overlay_fps"):
|
||||
overylay_fps.visible = true
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not is_on_floor():
|
||||
|
17
game/overlay_fps.gd
Normal file
17
game/overlay_fps.gd
Normal file
@@ -0,0 +1,17 @@
|
||||
extends CanvasLayer
|
||||
|
||||
@onready var text = $RichTextLabel
|
||||
@onready var timer = $Timer
|
||||
|
||||
func _ready() -> void:
|
||||
visible = false
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
text.clear()
|
||||
text.add_text("FPS: %s" % Engine.get_frames_per_second())
|
||||
|
||||
func _on_visibility_changed() -> void:
|
||||
if visible:
|
||||
timer.start()
|
||||
else:
|
||||
timer.stop()
|
1
game/overlay_fps.gd.uid
Normal file
1
game/overlay_fps.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dfns2snn6qqpw
|
@@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=19 format=3 uid="uid://dkldpdufpl28x"]
|
||||
[gd_scene load_steps=20 format=3 uid="uid://dkldpdufpl28x"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://5vty5riyfef2" path="res://Player.gd" id="1_4flbx"]
|
||||
[ext_resource type="Script" uid="uid://cad5seggccvp6" path="res://player_debug.gd" id="2_onrkg"]
|
||||
[ext_resource type="PackedScene" uid="uid://ditco83gy03gm" path="res://models/pistol.glb" id="3_hqtel"]
|
||||
[ext_resource type="Script" uid="uid://7ads6wescib" path="res://player_stats.gd" id="3_i3pqv"]
|
||||
[ext_resource type="Texture2D" uid="uid://cmldtn5n8a7vr" path="res://assets/textures/star_01.png" id="4_sweqy"]
|
||||
[ext_resource type="Script" uid="uid://dfns2snn6qqpw" path="res://overlay_fps.gd" id="5_2hs0m"]
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_fj7yv"]
|
||||
|
||||
@@ -42,6 +43,33 @@ material = SubResource("StandardMaterial3D_b26j0")
|
||||
size = Vector2(0.4, 0.4)
|
||||
orientation = 2
|
||||
|
||||
[sub_resource type="Animation" id="Animation_sweqy"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Head/PlayerCamera/pistol:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0.492394, -0.353437, -0.607601)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Head/PlayerCamera/pistol:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, 0.0417832, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_hqtel"]
|
||||
resource_name = "idle"
|
||||
length = 3.0
|
||||
@@ -72,33 +100,6 @@ tracks/1/keys = {
|
||||
"values": [Vector3(0, 0.0417832, 0), Vector3(-0.133121, 0.0421564, -0.00559862)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_sweqy"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Head/PlayerCamera/pistol:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0.492394, -0.353437, -0.607601)]
|
||||
}
|
||||
tracks/1/type = "value"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath("Head/PlayerCamera/pistol:rotation")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, 0.0417832, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_2hs0m"]
|
||||
resource_name = "move"
|
||||
loop_mode = 1
|
||||
@@ -187,6 +188,7 @@ skeleton = NodePath("../..")
|
||||
[node name="PlayerCamera" type="Camera3D" parent="Head"]
|
||||
|
||||
[node name="PlayerDebug" type="CanvasLayer" parent="Head/PlayerCamera"]
|
||||
visible = false
|
||||
script = ExtResource("2_onrkg")
|
||||
|
||||
[node name="PlayerDebugText" type="RichTextLabel" parent="Head/PlayerCamera/PlayerDebug"]
|
||||
@@ -210,6 +212,23 @@ draw_pass_1 = SubResource("PlaneMesh_n7ghd")
|
||||
transform = Transform3D(0.998255, -0.041771, 0.0417346, 0.041771, -4.37114e-08, -0.999127, 0.0417346, 0.999127, 0.00174477, 0.000758827, 0.0641694, -0.246936)
|
||||
target_position = Vector3(0, -50, 0)
|
||||
|
||||
[node name="OverlayFPS" type="CanvasLayer" parent="Head/PlayerCamera"]
|
||||
script = ExtResource("5_2hs0m")
|
||||
|
||||
[node name="RichTextLabel" type="RichTextLabel" parent="Head/PlayerCamera/OverlayFPS"]
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -117.0
|
||||
offset_bottom = 40.0
|
||||
grow_horizontal = 0
|
||||
size_flags_horizontal = 8
|
||||
size_flags_vertical = 0
|
||||
text = "FPS: 10.0"
|
||||
|
||||
[node name="Timer" type="Timer" parent="Head/PlayerCamera/OverlayFPS"]
|
||||
wait_time = 0.5
|
||||
|
||||
[node name="PlayerStats" type="Node" parent="."]
|
||||
script = ExtResource("3_i3pqv")
|
||||
|
||||
@@ -219,3 +238,6 @@ libraries = {
|
||||
}
|
||||
autoplay = "move"
|
||||
playback_default_blend_time = 0.05
|
||||
|
||||
[connection signal="visibility_changed" from="Head/PlayerCamera/OverlayFPS" to="Head/PlayerCamera/OverlayFPS" method="_on_visibility_changed"]
|
||||
[connection signal="timeout" from="Head/PlayerCamera/OverlayFPS/Timer" to="Head/PlayerCamera/OverlayFPS" method="_on_timer_timeout"]
|
||||
|
@@ -57,3 +57,8 @@ shoot={
|
||||
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(204, 17),"global_position":Vector2(213, 65),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||
]
|
||||
}
|
||||
overlay_fps={
|
||||
"deadzone": 0.2,
|
||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194333,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user