Traveller/scripts/FpsLabel.cs
Cold-Mint 92659d23b0
Prepare to add forks to the map.
准备为地图添加分叉。
2024-05-10 22:56:27 +08:00

56 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Godot;
namespace ColdMint.scripts;
/// <summary>
/// <para>FPSLabel</para>
/// <para>FPS标签</para>
/// </summary>
public partial class FpsLabel : Label
{
bool _enable;
private LabelSettings? _labelSettings;
public override void _Ready()
{
Text = null;
if (Config.IsDebug())
{
_labelSettings = new LabelSettings();
LabelSettings = _labelSettings;
_enable = true;
}
}
public override void _Process(double delta)
{
if (!_enable)
{
return;
}
var fps = Engine.GetFramesPerSecond();
Text = "FPS:" + fps;
if (_labelSettings != null)
{
//Green above 54 frames (smooth)
//在54帧以上为绿色流畅
if (fps > 54)
{
_labelSettings.FontColor = Colors.Green;
}
else if (fps > 48)
{
//Yellow between 48 and 54 frames (Karting)
//在48到54帧之间为黄色卡顿
_labelSettings.FontColor = Colors.Yellow;
}
else
{
//Red below 48 frames (lag)
//在48帧以下为红色
_labelSettings.FontColor = Colors.Red;
}
}
}
}