bgen/demo/scripts/fps_overlay.gd

19 lines
522 B
GDScript3
Raw Normal View History

2026-04-16 21:04:50 -04:00
extends CanvasLayer
# Cheap FPS + stats overlay. Attach as a child of any scene.
# The parent scene can call set_subtitle(text) to add a line below the FPS.
@onready var label: Label = $Label
var _subtitle := ""
func set_subtitle(text: String) -> void:
_subtitle = text
func _process(_delta: float) -> void:
var fps := Engine.get_frames_per_second()
var frame_ms := 0.0 if fps <= 0 else 1000.0 / fps
var txt := "FPS: %d %.2f ms" % [fps, frame_ms]
if _subtitle != "":
txt += "\n" + _subtitle
label.text = txt