FPS (frames per second), also known as frames per second. The more frames your computer displays per second, the smoother the game. FPS depends on network speed and computer hardware. To display the FPS of the Game you programmed with Godot Engine, follow the instructions below.
Join the channel Telegram belong to AnonyViet 👉 Link 👈 |
Display FPS for games using Godot Engine
FPS
First, you create 2 Nodes for yourself CanvasLayer and label.label. Label is a child node of canvaslayer
And I changed the label name -> fps label
You create yourself a script in Node World
In the declaration section, you declare yourself as follows
onready var fps_label = get_node("CanvasLayer/fps_label")
get_node()
is to get your node address
onready var
is to declare a variable that is always available, for example like this:
- A normal Var is a gun without bullets
- Onready var is a gun that is ready to be loaded
- Declare var in
_physical_process
then only whenphysical_process
works, then var will work
Add your own function func _process(delta)
:
_process(delta
)
: is the function called on each idle frame
_ physical _process
: is a function called on every physical frame
You can look it up in the godot documentation: https://docs.godotengine.org/en/3.0/classes/class_node.html#class-node-process
And if you use functions _process(delta)
: you need to enable it in function func _ready by command set_process(true)
And let's go back to the main part.
LIVE _process
Please type for yourself
func _process(delta):
fps_label.set_text("FPS: " + str(Engine.get_frames_per_second()))
After typing and running the game, you will see the fps displayed
Note: You must adjust the position of the label if you want to see fps
And you can also print FPS to the debug section in the following way
Project > Project Setting > Find FPS > click Debug Settings > Click Print FPS On > run the game and pay attention to debugging to see the fps displayed