FPS (frames per second) aka frames per second. The more frames your computer displays in a second, the smoother the game will be. FPS depends on network speed and computer hardware. To display the FPS of the Game programmed by you with Godot Engine, please follow the instructions below.
Join the channel Telegram belong to AnonyViet 👉 Link 👈 |
Display FPS for games using Godot Engine
FPS
First of all, you have to create 2 Nodes for yourself CanvasLayer and label. Label is a child node of canvaslayer
And I renamed the label -> 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 eg like this:
- The normal var is a gun without ammo
- Onready var is a gun that is ready to be loaded
- Declare var in
_physical_process
then only whenphysical_process
works then var it works
Add yourself a function func _process(delta)
:
_process(delta
)
: is the function called on every idle frame
_ physical _process
: is 1 function call on every physical frame
You can look it up in godot’s documentation: https://docs.godotengine.org/en/3.0/classes/class_node.html#class-node-process
And if you use the function _process(delta)
: you need to enable it in func _ready function with command set_process(true)
And back to the main part.
LIVE _process
you guys type yourself
func _process(delta):
fps_label.set_text("FPS: " + str(Engine.get_frames_per_second()))
After typing and running the game, the fps will be displayed
Note: You have to change the position of the label if you want to see the fps
And you can also print FPS to debug by the following way
Project > Project Setting > Find FPS > click Debug Settings > Click Print FPS On > run the game and notice the debug will see the fps displayed