1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:07:25 +08:00

Add smoothing to flashlight movement

This commit is contained in:
HoLLy 2019-05-13 01:31:47 +02:00
parent bcabc9d61f
commit f7806bc205

View File

@ -7,6 +7,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.MathUtils;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
@ -35,6 +36,9 @@ namespace osu.Game.Rulesets.Osu.Mods
private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition
{ {
private const double follow_delay = 120;
private double lastPositionUpdate;
public OsuFlashlight() public OsuFlashlight()
{ {
FlashlightSize = new Vector2(0, getSizeFor(0)); FlashlightSize = new Vector2(0, getSizeFor(0));
@ -48,7 +52,16 @@ namespace osu.Game.Rulesets.Osu.Mods
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
FlashlightPosition = e.MousePosition; var position = FlashlightPosition;
var destination = e.MousePosition;
double frameTime = Clock.CurrentTime - lastPositionUpdate;
double interp = Interpolation.ApplyEasing(Easing.Out, MathHelper.Clamp(frameTime / follow_delay, 0, 1));
FlashlightPosition = new Vector2(
(float)Interpolation.Lerp(position.X, destination.X, interp),
(float)Interpolation.Lerp(position.Y, destination.Y, interp)
);
lastPositionUpdate = Clock.CurrentTime;
return base.OnMouseMove(e); return base.OnMouseMove(e);
} }