mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 06:42:25 +02:00
Fix framerate dependent UI animations
This commit is contained in:
@@ -74,7 +74,7 @@ namespace Robust.Client.UserInterface.Controls
|
||||
else
|
||||
{
|
||||
_updating = true;
|
||||
Value = MathHelper.Lerp(Value, ValueTarget, Math.Min(args.DeltaSeconds * 15, 1));
|
||||
Value = UIAnimations.LerpAnimate(Value, ValueTarget, args.DeltaSeconds, 15);
|
||||
_updating = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace Robust.Client.UserInterface.CustomControls
|
||||
}
|
||||
else
|
||||
{
|
||||
_curAnchorOffset = MathHelper.Lerp(_curAnchorOffset, targetOffset, args.DeltaSeconds * 20);
|
||||
_curAnchorOffset = UIAnimations.LerpAnimate(_curAnchorOffset, targetOffset, args.DeltaSeconds, 20);
|
||||
}
|
||||
|
||||
UpdateAnchorOffset();
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Robust.Client.UserInterface;
|
||||
|
||||
internal static class UIAnimations
|
||||
{
|
||||
// From https://blog.pkh.me/p/41-fixing-the-iterative-damping-interpolation-in-video-games.html
|
||||
public static float LerpAnimate(float a, float b, float dt, float rate)
|
||||
{
|
||||
return MathHelper.Lerp(a, b, 1f - MathF.Exp(-dt * rate));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user