How Write Frame Per Second in game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Philagia

Hi Everyone,
I am lookin for today how i can display a fps counter top left of the window.
I tried like this:

func _process(delta):
a = get_node("../Sprite").position[0] - (OS.get_screen_size()[0]/2)
b = get_node("../Sprite").position[1] - (OS.get_screen_size()[1]/2)
rect_global_position = Vector2(a, b)

But it’s very “jerky”

:bust_in_silhouette: Reply From: kidscancode

I presume you are trying to reset its position because you have a Camera/Camera2D? Don’t do that.

The solution is to put your UI nodes under a CanvasLayer node. This will cause them to ignore the camera transform and remain “on top” of your game world as it moves around.

Thank you very much,
I can see the “Canvas Layer” but it does not display.

Philagia | 2019-08-25 19:01

It might help if you look at this example from the official tutorial:

kidscancode | 2019-08-25 19:03